My /etc/hosts file has 127.0.0.1 localhost line. When I try to connect to MySQL with mysql -u root -h localhost -p I get the ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) error. However, when I connect using 127.0.0.1, it works fine or using localhost with --protocol=TCP.
I read here that Unix treats host name localhost special and uses socket file instead of TCP/IP. Is it possible to connect to MySQL with socket file via terminal to not allow connections via the network?
Related
I'm properly establishing SSH tunnel and I can connect to MySQL users accesible via tcp connection but I don't know how to connect to users accesible only by unix socket. I know the correct socket location: /var/lib/mysql/mysql.sock and I can connect to it from the command line.
How do I connect via socket using HeidiSQL? Is this impossible when SSH tunnel is being used? When I enter '/var/lib/mysql/mysql.sock' into "Host/IP" then I get
Lost connection to MySQL server at 'handshake: reading initial communication packet', system error 22
UPDATE
My HeisiSQL connection settings:
Servers\ATLANTIS\SessionCreated<|||>1<|||>2020-08-14 13:03:22
Servers\ATLANTIS\Host<|||>1<|||>/var/lib/mysql/mysql.sock
Servers\ATLANTIS\WindowsAuth<|||>3<|||>0
Servers\ATLANTIS\CleartextPluginEnabled<|||>3<|||>0
Servers\ATLANTIS\User<|||>1<|||>atlantis
Servers\ATLANTIS\Password<|||>1<|||>7
Servers\ATLANTIS\LoginPrompt<|||>3<|||>0
Servers\ATLANTIS\Port<|||>1<|||>3306
Servers\ATLANTIS\NetType<|||>3<|||>2
Servers\ATLANTIS\Compressed<|||>3<|||>0
Servers\ATLANTIS\LocalTimeZone<|||>3<|||>0
Servers\ATLANTIS\QueryTimeout<|||>3<|||>30
Servers\ATLANTIS\KeepAlive<|||>3<|||>20
Servers\ATLANTIS\FullTableStatus<|||>3<|||>1
Servers\ATLANTIS\Databases<|||>1<|||>
Servers\ATLANTIS\Library<|||>1<|||>libmariadb.dll
Servers\ATLANTIS\Comment<|||>1<|||>
Servers\ATLANTIS\StartupScriptFilename<|||>1<|||>
Servers\ATLANTIS\TreeBackground<|||>3<|||>536870911
Servers\ATLANTIS\SSHtunnelHost<|||>1<|||>atlantis.localdomain
Servers\ATLANTIS\SSHtunnelHostPort<|||>3<|||>22
Servers\ATLANTIS\SSHtunnelUser<|||>1<|||>atlantis
Servers\ATLANTIS\SSHtunnelPassword<|||>1<|||>6
Servers\ATLANTIS\SSHtunnelTimeout<|||>3<|||>4
Servers\ATLANTIS\SSHtunnelPrivateKey<|||>1<|||>C:\secure-folder\private-key.ppk
Servers\ATLANTIS\SSHtunnelPort<|||>3<|||>3307
Servers\ATLANTIS\SSL_Active<|||>3<|||>0
Servers\ATLANTIS\SSL_Key<|||>1<|||>
Servers\ATLANTIS\SSL_Cert<|||>1<|||>
Servers\ATLANTIS\SSL_CA<|||>1<|||>
Servers\ATLANTIS\SSL_Cipher<|||>1<|||>
Servers\ATLANTIS\IgnoreDatabasePattern<|||>1<|||>
Servers\ATLANTIS\RefusedCount<|||>3<|||>5
Remotely, the command should be executed like: mysql -u mySqlUser -p mySqlPw -h localhost.
ssh remote-user#remote "mysql -u mySqlUser -p mySqlPw -h localhost"
As from there, you should be able to do your stuff
I am able to access mysql via workbench with hostname: localhost and port: 3306 which were present by default, but I can't connect it via bash
mysql -u root -p
returns follwing error:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
How to connect mysql in docker via bash?
You need to use the -h arugument:
mysql -h 127.0.0.1 -u root -p
The error message tells you that mysql tried to connect to the unix socket /var/run/mysqld/mysqld.sock and not to the network socket.
I have mysql/mysqli installed on my local machine via MacPorts and can access mysql/mysqli commands from the command line ONLY when using locahost.
If I try running:
mysql -u root -h 127.0.0.1 -p
I get the following error:
ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (61)
When running:
mysql -u root -h localhost -p
Everything is fine.
The reason this bothers me is that I am trying to use mysqli_connect in a PHP script running on localhost. When I enter the host as localhost, it gives me this error:
Warning: mysqli_connect(): (HY000/2002): No such file or directory in ... on line 2
bool(false) Failed to connect to MySQL: No such file or directory
And when I enter the host as 127.0.0.1, I get a different error:
Warning: mysqli_connect(): (HY000/2002): Connection refused in /Users/raph/coding/webroot/rugapp/qbo-palmer/docs/partner_platform/example_app_ipp_v3/test.php on line 2
bool(false) Failed to connect to MySQL: Connection refused
It seems as though I have some configuration problems. What is the best way to fix them?
The connection to localhost uses a unix socket. It seems the correct socket path is built into the mysql binary you use, which explains why it works on the command line. For the unix socket connection to work from PHP, you need to specify MacPorts MySQL's non-standard socket path as you would normally specify a port number.
For the failure to connect using 127.0.0.1 (which forces IPv4 and avoids the unix socket), see mysql running but cannot connect to 127.0.0.1.
I installed mysql server 5.6, and I can connect to it using mysql workbench, but I'm wondering if I can connect to it from Vagrant box, and I tried the following command, but failed:
vagrant#sdi03:~$ mysql -h 127.0.0.1 --port=3366 -u root -p
Enter password:
ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111)
Note that I purposely run the mysql server on port 3366 instead of 3306, because I have another mysql server running on Vagrant box on port 3306.
I'm using success connect to ip adress of my windows, it's 192.168.1.55
mysql -u konst -p -h 192.168.1.55
PS I can't connect with root, i create new mysqluser konst with admin's rights
I'm trying to connect to the mysql server on my mac using terminal. I've already got MAMP on my mac but now I have installed XAMPP. when I type this into my terminal
mysql -u root -p
it comes up with this message...
ERROR 2002 (HY000): Can't connect to local MySQL server through socket
'/Applications/MAMP/tmp/mysql/mysql.sock' (2)
I'm wondering is it because of XAMPP? Any suggestions?
have you tried
mysql -h 127.0.0.1 -u root -p
(if the mysql server isn't running on your local box, substitute the IP address of the mysql server for 127.0.0.1)