I'm using Linux and I recently downgraded MySQL to 5.6 from 5.7 (due to some issues because of its strictness). Now when I use command mysql, I get the error:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
I have checked several posts and systemctl mysql startseems to work. But everytime I reboot my system, I have to use systemctl mysql start again to start MySQL.
Also, service start mysql doesn't work.
There is no /etc/my.cnf file, only /etc/mysql/my.cnf file. I'm using Ubuntu 16.04.
How can I configure it so that the MySQL service starts at boot?
Edit:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
This post is unable to help either.
Basically, if mysql command is running without a host, it looks for a socket file on your local machine (this lets it connect to the running process directly). You have two workarounds. One is to include host in your mysql connection command mysql -u root -p -H 127.0.0.1, the other is to modify my.cnf to include:
[mysqld]
socket=/var/run/mysqld/mysqld.sock
[client]
socket=/var/run/mysqld/mysqld.sock
see here for more.
Related
Since I've updated my Mac to the lastest OS version (Ventura 13.2) and I'he made some cleanup (hopefully I didn't remove any important file). I can't connect to mySql
I've insatlled mysql with brew (long before this update) and it always has worked fine.
When I run brew services start mysql in my terminal it looks to work (Successfully started mysql (label: homebrew.mxcl.mysql))
But, as soon as I run mysql -u root -p and I enter my password I have the following error message ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
When I explore /tmp directory I see that /tmp/mysql.sock is a symlink to /var/lib/mysql/mysql.sock but mysql directory doesn't exist in /var/lib.
After extensive research I didn't find how to "get" this directory.
I've found many entries in StackOverflow with the same title, I've tried almost all answer but none seems to work. especialy in my case I'm using brew and macOS ventura.
Typicaly for ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' the accepted answer is not about brew.
I've tried brew reinstall mysql.
I've tried as well mysql -h 127.0.0.1 -u root -p in this case the error is ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1:3306' (61).
I've tried to run mysqld and then brew services start mysql, in this case I have the following error
Bootstrap failed: 5: Input/output error
Try re-running the command as root for richer errors.
Error: Failure while executing; `/bin/launchctl bootstrap gui/502 /Users/CedMacBook1/Library/LaunchAgents/homebrew.mxcl.mysql.plist` exited with 5.
I've tried to change my password using sudo mysqladmin -u root password -p and once again I have the error error: 'Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)'.
It looks like mysql is runningm, I've ran ps aux | grep mysqld and get the following line:
CedMacBook 21853 0,0 0,0 34400496 2728 s000 S+ 7:53 0:00.01 grep mysqld
Finally I've checked my /usr/local/etc/my.cnf and I have the following
# Default Homebrew MySQL server config
[mysqld]
socket=/tmp/mysql.sock
# Only allow connections from localhost
bind-address = 127.0.0.1
port=3306
mysqlx-bind-address = 127.0.0.1
At this stage I'd be happy to swipe out everything... if I could save all my database
Please help, I don't know what else to try
I tried a lot to install MySQL8 via Homebrew on Mac 10.14.5. I was running MySQL 5.7 before that and did the following: I removed MySQL completely via this tutorial: https://coderwall.com/p/os6woq/uninstall-all-those-broken-versions-of-mysql-and-re-install-it-with-brew-on-mac-mavericks
After that I run mysql and got the message that the command was not known. So I installed mysql with brew install mysql. After installation I did brew link --force mysql and got Warning: Already linked: /usr/local/Cellar/mysql/8.0.19
I edited /usr/local/etc/my.cnf and added default-authentication-plugin=mysql_native_password in the [mysqld] section. After that I restartet the service using brew services restart mysql
brew services list shows me this now:
mysql started root /Library/LaunchDaemons/homebrew.mxcl.mysql.plist
mysql#5.7 stopped
However, when I type mysql in the terminal I get this:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
The /tmp/mysql.sock does not exist.
When I change the host in the my.cnf file from localhost to 127.0.0.1 this error will change into this:
ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 54
Anyone has an idea what's going on here and how I can fix it? I also googled it and found various Threads, some are saying that the permissions must be changed to this sudo chown -R _mysql:mysql /usr/local/var/mysql but this does not change anything in my case.
I have mysql database which was working fine earlier. After getting too many connections error. I have increased max connection and restarted my centos server. But after restart I used below command to connect to server.
mysql -uroot -p
But I am getting below errors.
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2).
I tried all the options available on google. But it didn't worked for me. Some are saying to reinstall mysql, but I have data in GB's which I don't want to lost. Please can anyone help me to solve this problem.Thanks in advance.
Make sure you are indexing the right socket file.
Try this and provide the output.
check the socket in the my.cnf
cat /etc/my.cnf | grep -i socket
I have just installed xampp on Mac.
I was trying to import an existing .sql file to MySQL DB on phpMyAdmin.
It was a success.
But I cannot connect MySQL using mysql browser like Sequel Pro.
I think this is because of ERROR (2002)
This is the result when I type mysql on the terminal.
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock' (2 "No such file or directory")
Please help me how to fix this issue.
Have you checked it out here.
It means either the MySQL server is not installed/running, or the file mysql.sock doesn’t exist in /var/lib/mysql/.
There are a couple of solutions for this error.
First, check to see whether mysqld service is running or not. If not, start it:
service mysqld start
Then try to connect again.
Try to connect to 127.0.0.1 instead of localhost
If you connect to localhost, it will use the socket connector, but if you connect to 127.0.0.1 the TCP/IP connector will be used. So when the socket connector is not working, try connecting to 127.0.0.1 instead.
Edit file my.cnf
Find the file my.cnf (usually in /etc/) to edit and add these following line:
[mysqld]
socket=/var/lib/mysql/mysql.sock
[client]
socket=/var/lib/mysql/mysql.sock
Restart mysql and connect again.
Symlink
In some cases, you mysql.sock might be located in another folder. You have to find and symlink it. You might find it in /tmp/mysql.sock or /data/mysql_datadir/mysql.sock
For example, your file is located as in /tmp/mysql.sock
Then symlink it:
ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
Restart mysql and connect again.
Whenever I try to connect to MySQL to access phpmyadmin, it returns an error:
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (13)
I also tried to start MySQL through my server's terminal:
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)
When I restarted MySQL it displayed:
Stopping MySQL database server mysqld
df: `/var/lib/mysql/.': No such file or directory
df: no file systems processed
/etc/init.d/mysql: ERROR: The partition with /var/lib/mysql is too full!
How might I resolve this?
I've seen that a couple of times. It has meant that the actual MySQL server instance was down for some reason. It was fixed by a simple call to:
service mysql restart
Edit
I just noticed your comment The partition with /var/lib/mysql is too full!. This means your drive is too full to run MySQL. You need to either talk to your server administrator or just clean up the HD, but this will keep breaking until more room is available.
Normally this happens when you have don't have the mysql daemon started. most distros you can start it by typing in
/etc/init.d/mysqld start
and that should get you going. I think it can sometimes also be that after you did your install you will need to give root a password.
mysqladmin -u root password <enter password here>
You may want to check first that the dameon is atually running by doing a
ps -ef | grep mysql
Credit