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.
Related
While installing MySQL I am facing following error:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
but when I tried with host address it actually started
mysql -h 127.0.0.1 mysql -u root -p
why I am not getting logged in without hostname?
I'm trying to connect to a local installation of MariaDB 10xx via the mysql command line application but despite specifying a host and a port I get an error the client cannot connect via the unix socket.
This is my my.cnf:
⟩ sudo vi /opt/local/etc/mariadb-10.1/my.cnf
# Use default MacPorts settings
!include /opt/local/etc/mariadb-10.1/macports-default.cnf
[mysqld]
socket=/private/tmp/mysqld.sock
port=3306
log_error=/private/tmp/mysql_error.log
log_warnings=3
general-log
general-log-file=/private/tmp/mariadb_queries.log
log-output=file
This is the command line I use:
mysql -u root --host localhost --port 3306 --password
And this is the error:
⟩ mysql -u root --host localhost --port 3306 --password
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/opt/local/var/run/mariadb-10.1/mysqld.sock' (2 "No such file or directory")
I'm trying to check whether MariaDB is listening to TCP connections.
So I asked in the MariaDB IRC channel and apparently passing localhost to MariaDB causes it to use the unix socket. Replacing --host localhost with --host 127.0.0.1 did the trick.
When I login without specifying host name, I could not login
mysql -u root -p
It displays the message
ERROR 2002 (HY000): Can't connect to local MySQL server through socket
'/var/lib/mysql/mysql.sock' (2)
But if I use hostname, I am able to login
mysql -h 127.0.0.1 -P 3306 -u root -p
It didn't allow, even if I use localhost as my hostname
What is the reason for this?
I would check that mysql is started
service mysqld start
I have mysql container on docker. Mysql is running correcty now(because my application is running).
When I type docker-compose ps I see mysql is up. This is related part in pom.xml :
<driver>com.mysql.jdbc.Driver</driver>
<url>jdbc:mysql://127.0.0.1:3310/fraud_dev</url>
<defaultSchemaName>abc_dev</defaultSchemaName>
<username>abc_dev</username>
<password>abc_dev_123</password>
I am trying to connect mysql on localhost terminal. I am typing this :
mysql -u 'abc_dev'#'localhost:3310' -p
I am typing password. Then I am getting this error:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
I dont know where I am wrong. How can I fix it?
Thanks.
You do not use the standard mysql port 3306. Because of this you have to specify the used port with
mysql -u abc_dev -p -h localhost --port 3310
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