我的问题开始与我不能登录根在我的mysql安装更多。我试图运行mysql没有密码打开…但每当我执行命令时

# mysqld_safe --skip-grant-tables &

我再也拿不回提示了。我试图按照这些说明恢复密码。

屏幕看起来是这样的:

root@jj-SFF-PC:/usr/bin# mysqld_safe --skip-grant-tables
120816 11:40:53 mysqld_safe Logging to syslog.
120816 11:40:53 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

我没有得到开始输入SQL命令重置密码的提示。

当我按CTRL + C杀死它时,我得到以下消息:

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

Check that mysqld is running and that the socket: '/var/run/mysqld/mysqld.sock' exists!

如果我重试该命令并将其放置足够长的时间,我确实会得到以下一系列消息:

root@jj-SFF-PC:/run/mysqld# 120816 13:15:02 mysqld_safe Logging to syslog.
120816 13:15:02 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
120816 13:16:42 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

[1]+  Done                    mysqld_safe --skip-grant-tables
root@jj-SFF-PC:/run/mysqld#

但如果我尝试以root用户登录,执行以下操作:

# mysql -u root

我得到以下错误消息:

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

/var/run/mysqld/mysqld.Sock文件不存在。文件夹有,但文件没有。

此外,我不知道这是否有帮助,但我运行find / name mysqld,它出现了:

/var/run/mysqld - folder
/usr/sbin/mysqld - file
/run/mysqld - folder

我不知道这是否正常。但我把这些信息也包括进来,以防有用。

我最终决定卸载并重新安装mysql。

apt-get remove mysql-server
apt-get remove mysql-client
apt-get remove mysql-common
apt-get remove phpmyadmin

在按照上面相同的顺序重新安装所有包之后,在phpmyadmin安装期间,我得到了相同的错误:

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

所以我再次尝试卸载/重新安装。这一次,在我卸载包之后,我还手动将所有mysql文件和目录重命名为mysql。在各自的位置都不好。

/var/lib/mysql 
/var/lib/mysql/mysql
/var/log/mysql
/usr/lib/perl5/DBD/mysql
/usr/lib/perl5/auto/DBD/mysql
/usr/lib/mysql
/usr/bin/mysql
/usr/share/mysql
/usr/share/dbconfig-common/internal/mysql
/etc/init.d/mysql
/etc/apparmor.d/abstractions/mysql
/etc/mysql

然后我尝试重新安装mysql-server和mysql-client。但我注意到它并没有提示我输入密码。它不是应该要求输入管理员密码吗?


当前回答

mysql。sock文件在MariaDB启动时创建,在MariaDB关闭时删除。如果MariaDB不运行,它就不存在。 也许你没有安装MariaDB。 你可以按照下面的说明操作: https://www.linode.com/docs/databases/mariadb/how-to-install-mariadb-on-centos-7 最好的

其他回答

这一点已经被提到过几次了,但这对我来说立即起了作用:

Service mysql restart

对我来说唯一有效的方法是从我的系统中完全卸载MYSQL。所以我做了以下事情:

sudo apt-get remove mysql-server -y
sudo rm -r /var/lib/mysql
sudo rm -r /etc/mysql
sudo apt-get remove mysql-client -y
sudo apt-get remove mysql-common -y
sudo apt-get remove phpmyadmin -y
sudo apt-get install mysql-server -y

解决方法简单多了。

First, you have to locate(in Terminal with "sudo find / -type s") where your mysql.sock file is located. In my case it was in /opt/lampp/var/mysql/mysql.sock Fire up Terminal and issue sudo Nautilus This starts your Files manager with super user privileges From Nautilus navigate to where your mysql.sock file is located Right click on the file and select Make Link Rename the Link File to mysqld.sock then Right click on the file and Cut it Go to /var/run and create a folder called mysqld and enter it Now right click and Paste the Link File Voila! You will now have a mysqld.sock file at /var/run/mysqld/mysqld.sock :)

确保您无法访问的套接字文件路径与'/var/run/mysqld/mysqld相同。Sock ',否则改变你的路径。 停止mysqld

$ sudo /etc/init.d/mysqld stop

如果进程仍在运行;

$ sudo pkill -9 mysqld

删除将要创建socket的mysql目录。对我来说,它不允许移除,所以我必须用力移除。

$ sudo mkdir -p /var/run/mysqld

设置目录的所有权

$ sudo chown mysql:mysql /var/run/mysqld

启动mysql

$ sudo /etc/init.d/mysql start

尝试连接mysql

$ sudo mysql -u dbuser -p

用户加载步骤的答案对我来说是有效的。 有时需要编辑/etc/mysql/my.cnf文件添加行到客户端

[client]
password = your_mysql_root_password
port  = 3306
host  = 127.0.0.1
socket  = /var/lib/mysql/mysql.sock