我的问题开始与我不能登录根在我的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。但我注意到它并没有提示我输入密码。它不是应该要求输入管理员密码吗?


当前回答

在lampp中,正如我所认识的,它不识别mysql命令。 试着用

sudo /opt/lampp/bin/mysql

它将打开mysql终端,在那里你可以与数据库通信。

其他回答

我的情况是,/etc/目录中的mysql被重命名为mysql_bk,只需复制mysql_bk即可

sudo cp -r /etc/mysql_bk/ /etc/mysql/

then

service mysql restart

如果你有“Unit mysql.”服务未发现"错误,请安装"sudo apt-get install mysql-server"

解决方法简单多了。

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 :)

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

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

错误2002 (HY000):无法通过套接字/var/lib/ MySQL / MySQL连接到本地MySQL服务器。袜子”(2)

在/etc/my.cnf中添加以下行:

[client]
socket=/var/lib/mysql/mysql.sock <= this path should be also same as is[mysqld]

然后重新启动服务: Service mysql restart

这对我很有效