Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MySQL connection refused using Unix Socket #1065

Closed
mason-chase opened this issue Apr 12, 2020 · 4 comments
Closed

MySQL connection refused using Unix Socket #1065

mason-chase opened this issue Apr 12, 2020 · 4 comments
Assignees

Comments

@mason-chase
Copy link

I'm trying to connect to MySql server through Unix Socket instead of TCP for maximizing connection and reducing processing load.

My Asp Net Core app is running in Docker Swarm and I'm running Percona docker
I'm sharing mysqld.sock using volume sharing and on Asp Net core container I am able to login to console and make connection to the server using mysql client
/var/run/mysqld/mysqld.sock

However when Asp Net Core application is trying to connect to server it is switching from localhost to 127.0.0.1:3306 even though I set no port and SslMode=none

Any help is much

Exception message:
Stack trace:
MySql.Data.MySqlClient.MySqlException (0x80004005): Unable to connect to any of the specified MySQL hosts.
 ---> System.AggregateException: One or more errors occurred. (Connection refused 127.0.0.1:3306)
 ---> System.Net.Internals.SocketExceptionFactory+ExtendedSocketException (111): Connection refused 127.0.0.1:3306

Further technical details

MySQL version: 5.7
Operating system: ubuntu:latest
Pomelo.EntityFrameworkCore.MySql version: 3.1.1
Microsoft.AspNetCore.App version: 3.1

@lauxjpn lauxjpn self-assigned this Apr 12, 2020
@lauxjpn
Copy link
Collaborator

lauxjpn commented Apr 12, 2020

This question is targeted at MySqlConnector, the underlying library used by Pomelo for MySQL communication.

To use Unix sockets, you need to set the connection protocol to Unix. The Server option then becomes the path to the socket file. The following shows a sample connection string:

server=/var/run/mysqld/mysqld.sock;protocol=unix;database=mydatabase

See MySQL .NET Connection String Options for further details.

@mason-chase
Copy link
Author

You are really awesome Lauxjpn, I really wish this was in Pomelo document and samples to save a lot of times, I was not aware that Pomelo is using MySqlConnector underneath @lauxjpn

@lauxjpn
Copy link
Collaborator

lauxjpn commented Apr 13, 2020

I really wish this was in Pomelo document and samples to save a lot of times

Unfortunately, both documentation and samples are lacking at the moment. We really need to improve upon that before the .NET 5 release.

I provided a lot of sample code inside of issues, but we should consolidate them into multiple samples and make them part of the repo.

I was not aware that Pomelo is using MySqlConnector underneath

It is stated on our main repo page, but there is a lot of stuff there and its easy to overlook.

@mguinness
Copy link
Collaborator

I really wish this was in Pomelo document and samples to save a lot of times

@mason-chase This is a community project, so if you wish to contribute your PR would be welcomed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants