I have XAMPP running on my desktop and can connect to the MySQL server via phpMyAdmin. However, when I try to connect through Cygwin:
Error: Can't connect to local MySQL server through socket '/var/run/mysql.sock' (2)
I've tried connecting to MySQL on the same machine, my local dev server and my remote server, all failed.
mysql -h 127.0.0.1 -P <PORT> -u root -p
This is what worked for me. Make sure you check what is the correct port.
Check the mysqld PID with:
ps -sW | grep mysqld
And then find the PORT with:
netstat -nao | grep <PID>
Have fun!
you can also add the alias of itself.
alias mysql = 'mysql -u {user} -p{password} -h 127.0.0.1'
Related
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 created my container like this:
$ docker run -d -p 33060:3306 myimage
Then I try connect from host to mysql server in container:
$ mysql -uroot -proot -P 33060
I got this error:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
It odd because in Navicat only I changed the port and work fine:
But If I have the IP of the container:
$ docker inspect --format '{{ .NetworkSettings.IPAddress }}' mycontainer
172.17.0.55
Then I can connect to mysql server successfully:
$ mysql -uroot -proot -h 172.17.0.55
But it is a tedious task have to check the ip each time I create a new container to connect to mysql. There any settings I can do to make this task simpler?
This is not a Docker issue. By default the mysql command-line client will connect to a local (Unix) socket instead of a network one, even if you specify -P.
This behavior is described in the documentation:
On Unix, MySQL programs treat the host name localhost specially, in a way that is likely different from what you expect compared to other network-based programs. For connections to localhost, MySQL programs attempt to connect to the local server by using a Unix socket file. This occurs even if a --port or -P option is given
You have to pass the -hlocalhost option, or you can set your connection defaults in /etc/mysql/my.cnf
I am trying to setup iRedMail but during the installation process I get this error:
ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111)
and by default iRedMail tries to connect to MySql with TCP and not with a system socket.
To narrow down the problem, the following works:
mysql -h localhost -P 3306 -u root -p
but this does not
mysql -h 127.0.0.1 -P 3306 -u root -p
ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111)
I am using mysql Ver 14.14 on Ubuntu 14.04
Here are the relevant configuration lines of /etc/mysql/my.cnf:
skip-networking=0
bind-address = 127.0.0.1
Also, mysql> SHOW VARIABLES; shows that
skip_networking | ON
Here are the relevant lines of px aux | grep mysql:
mysql /usr/sbin/mysqld --basedir=/usr --datadir=/mnt/storage/data/mysql/ --plugin- dir=/usr/lib/mysql/plugin --user=mysql --log-error=/var/log/mysql/error.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/run/mysqld/mysqld.sock --port=3306
= EDIT =
The main question here is how to turn off skip_networking
Check your Firewall.
Or use Socket connection.
start mysql service then try
sudo service mysqld start
for installation of mysql in ubuntu
sudo apt-get install mysql-server mysql-client
It looks like you are using skip-networking and bind-address at the same time. You should never do this.
skip-networking disables TCP/IP - so just remove it.
bind-address means you are using TCP/IP.
Hi I am using Linux/Ubuntu and I am having a problem on logging in on mysql
when I run the code:
sudo mysql -h localhost -u root -p
I got an error that says:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/obitnami/mysql/tmp/mysql.sock' (2)
How can I fix this?
I am using:
mysql Ver 14.14 Distrib 5.5.22, for debian-linux-gnu (x86_64) using readline 6.2
rails 3.2.3
ruby 1.9.3
Please help
First you can try to see if it is running at all with command
ps aux | grep mysql
Mysqld should be there.
Check also if listening address, because it might be your outside address instead of localhost with command:
netstat -antp |grep mysql
Then check your config file to see where exactly your socket file is being written. After that you have verified that it's up and running you can try to connect to it with command
mysql -u root -p -S /path/to/socket.file
It's possible that you have socket file on other place and because of it you can't connect to server. -h localhost is not needed if you are connecting to localhost because it's assumed if -h is not used that you are connecting locally but it might be needed if your listening IP address is external one and not internal (127.0.0.1 for localhost or 0.0.0.0 for all addresses).
I've got mysql 5.1 on a windows xp machine. It's listening on port 3308. I'm trying to use mysqldump:
> mysqldump -u root -pmypassword dbname > out.sql
Getting an error:
mysqldump: Got error: 2003: Can't connect to MySQL server on 'localhost' (10061) when trying to connect
Not sure what the problem is, looking at --help dumps variables and shows port=3308 as I set in the mysql installation (instead of default 3306). I don't think there's anything different with my installation. I also tried explicitly setting the port # on the command line but still same error.
Thanks
To connect through a port (and not the default 3306), use:
mysqldump -u root -pmypassword -P 3308 dbname > out.sql
Besides that, a simple test to see if MySQL responds at port 3308 is to try telneting:
telnet 127.0.0.1 3308
If MySQL is listening on port 3308, it'll respond with an error and the version running.
Go to run type services.msc
then
locate mysql service and start it .this solved
If your Mysql-Client is 5.5.16 please upgrade it to 5.6.10, this process worked for me if your mysql server is 5.6.10.