Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

mariadb - Can't connect to local mysql server - error 2002

I have what seems to be a common error, but all of the solutions I've found online aren't working for me.

I've been following a tutorial to display a MySQL table to a website in realtime (found here), and one of the first steps was to edit the MYSQL config file at /etc/mysql/my.cnf

[mysqld]
server-id = 1
log_bin  = /var/log/mysql/mysql-bin.log #Or c:/logs/mysql-bin.log
expire_logs_days = 10
max_binlog_size = 100M
binlog-format = row

However, when I inserted this into the config file and restarted the MYSQL server as instructed, the server wouldn't start, throwing me the error:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

In hindsight, I should have just taken out the faulty lines of code from my config file, but I instead uninstalled MySQL and MariaDB thinking it was an error on the side of MySQL and reinstalled them. I'll include the lines of code I ran to do this below to ensure I didn't miss anything.

sudo apt remove --purge mysql-server mysql-client mysql-common
sudo apt autoremove
sudo mv -iv /var/lib/mysql /var/tmp/mysql-backup
sudo rm -rf /var/lib/mysql*
sudo apt install mysql-server

I then tried restarting the MySQL server with the following:

service mysql restart
 /etc/init.d/mysqld restart
sudo systemctl start mysql

AFter this didn't work, I tried deleting all the contents of /var/lib/mysql and running the following line as instructed in another solution to this issue, which also didn't work.

mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql

Even after reinstalling, it appears I am missing the /etc/mysql folder and the my.cnf file. I tried the line below to create it, but it doesn't work:

sudo dpkg-reconfigure mysql-server-5.7

Have I missed a step? Help is definitely appreciated.

question from:https://stackoverflow.com/questions/65545797/cant-connect-to-local-mysql-server-error-2002

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...