Getting a socket error when trying to connect to MySQL
I updated my Linode from Debian 8 to 11, and this has caused multiple issues. I'm aware this was a very silly thing to do, and I didn't even have any real backup strategy.
But anyway, I'm setting up a new Linode and trying to migrate everything over. I need to get a backup of my MySQL database, but when I try to access MySQL, I get the following error:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
sudo find / -type s | grep mysql
returns nothing. So it looks like there is no socket file present. I have confirmed that MySQL is in fact running, by entering:
systemctl status mysql
The output is:
? mysql.service - LSB: Start and stop the mysql database server daemon Loaded: loaded (/etc/init.d/mysql; generated) Active: active (exited) since Thu 2021-12-02 14:25:19 GMT; 18min ago Docs: man:systemd-sysv-generator(8) Process: 2643 ExecStart=/etc/init.d/mysql start (code=exited, status=0/SUCC> CPU: 2ms Dec 02 14:25:19 odaiba systemd: Starting LSB: Start and stop the mysql datab> Dec 02 14:25:19 odaiba systemd: Started LSB: Start and stop the mysql databa> lines 1-9/9 (END)
I ran this command:
which returned the following output:
# The MariaDB configuration file # # The MariaDB/MySQL tools read configuration files in the following order: # 0. "/etc/mysql/my.cnf" symlinks to this file, reason why all the rest is read. # 1. "/etc/mysql/mariadb.cnf" (this file) to set global defaults, # 2. "/etc/mysql/conf.d/*.cnf" to set global options. # 3. "/etc/mysql/mariadb.conf.d/*.cnf" to set MariaDB-only options. # 4. "~/.my.cnf" to set user-specific options. # # If the same option is defined multiple times, the last one will apply. # # One can use all long options that the program supports. # Run program with --help to get a list of available options and with # --print-defaults to see which it would actually understand and use. # # If you are new to MariaDB, check out https://mariadb.com/kb/en/basic-mariadb-/ # # This group is read both by the client and the server # use it for options that affect everything # [client-server] # Port or socket location where to connect # port = 3306 socket = /run/mysqld/mysqld.sock # Import all .cnf files from configuration directory !includedir /etc/mysql/conf.d/ !includedir /etc/mysql/mariadb.conf.d/
There is no /run/mysqld directory. I created it, and restarted MySQL, but this seemed to make no difference. I'm not sure how to set this my.cnf file to properly define or create the socket.
I'm also a little confused about all the references to MariaDB. Could that be something to do with the issue?
Any help at all is hugely appreciated!!
The first thing to check is the logs in /var/log/ to see if anything comes up that references mysql or mariadb. There may even be a specific folder in /var/log for mysql/mariadb logs to check for any problems. If everything looks fine there or if there's no info, then you may want to try uninstalling then reinstalling mariadb or mysql, whichever you installed the first time around.
Just as a warning this could break things in itself but shouldn't result in a loss of data. I'd recommend doing this only if you can't find another way to get it running. You may want to take a backup of the entire DBMS just in case. This guide has an example of how to do so for MySQL:
To reinstall mariadb, as an example:
sudo apt remove mariadb-server sudo apt install mariadb-server
You can also run
apt purge mariadb-server if that doesn't work.