我在Ubuntu 12.04 LTS (Precise穿山甲)上安装了LAMP,然后在phpMyAdmin上设置根密码。我忘记密码了,现在无法登录。当我试图通过终端更改密码时,我得到:
错误2002 (HY000):无法通过套接字连接到本地MySQL服务器 ' / var /运行/ mysqld / mysqld。袜子”(2)
我该如何解决这个问题?我无法打开LAMP,卸载它或重新安装它。
我在Ubuntu 12.04 LTS (Precise穿山甲)上安装了LAMP,然后在phpMyAdmin上设置根密码。我忘记密码了,现在无法登录。当我试图通过终端更改密码时,我得到:
错误2002 (HY000):无法通过套接字连接到本地MySQL服务器 ' / var /运行/ mysqld / mysqld。袜子”(2)
我该如何解决这个问题?我无法打开LAMP,卸载它或重新安装它。
当前回答
首先,尝试重新启动它
停止mysql服务
启动mysql服务
如果以上还不能解决问题,那就走吧……
完全卸载MySQL
sudo apt-get remove --purge mysql\*
重新安装它
sudo apt install mysql-server mysql-client
测试它是否运行
sudo mysql
安装php驱动程序
sudo apt install php7.4 php7.4-fpm php7.4-mysql php7.4-cgi php7.4-cli php7.4-common
你可以用php7替换php7.4。X或php8.0.12或更高版本 非常好!
❗️小心,如果没有保存,您将丢失数据。如果可能的话,请备份您的数据。
其他回答
检查my.conf (/etc/mysql/my.cnf),看看bind-address是否设置为127.0.0.1。
如果不是,这可能会导致此问题。
如果您的安装是最近的,您应该确认您的安装是否是安装服务器…mysql -服务器- 5.5 . .可能你只安装了“mysql”..这只是客户端而不是服务器。
如果您的Linux机器上安装了XAMPP,请尝试将my.cnf文件从/opt/lampp/etc/my.cnf复制到/etc/my.cnf
然后,再次运行mysql -u root…现在您应该有了正确的套接字,并且能够运行MySQL客户端。
This error can also occur if you try to change the directory where the database is stored, but imput the wrong directory in the configuration file (like a typo in the second drive as D instead of the accurate D_). Instead of telling you the typo directory does not exist, it will tell you that you lack permission to access it (leading you to try to change the permissions for the typo directory, which it will let you do). So if you get this error while changing directories, double check the configuration file and make sure you don't have a typo.
我也遇到了这个问题,但我刚刚遇到了:
sudo service mysql restart
这对我很管用。