我在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,卸载它或重新安装它。
当前回答
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.
其他回答
我看到所有这些答案,但没有一个提供重置密码的选项,没有接受的答案。实际的问题是他忘记了密码,所以他需要重置,而不是像大多数答案所暗示的那样,看看它是否正在运行(安装与否)。
重置密码
遵循以下步骤(如果你真的忘记了密码,这可能会有帮助,你可以随时尝试,即使你现在没有这种情况):
Stop mysql sudo /etc/init.d/mysql stop Or for other distribution versions: sudo /etc/init.d/mysqld stop Start MySQL in safe mode sudo mysqld_safe --skip-grant-tables & Log into MySQL using root mysql -u root Select the MySQL database to use use mysql; Reset the password -- MySQL version < 5.7 update user set password=PASSWORD("mynewpassword") where User='root'; -- MySQL 5.7, mysql.user table "password" field -> "authentication_string" update user set authentication_string=password('mynewpassword') where user='root'; Flush the privileges flush privileges; Restart the server quit Stop and start the server again Ubuntu and Debian: sudo /etc/init.d/mysql stop ... sudo /etc/init.d/mysql start
在CentOS、Fedora和RHEL上:
sudo /etc/init.d/mysqld stop
...
sudo /etc/init.d/mysqld start
使用新密码登录 Mysql -u root -p 输入新密码,再次享受您的服务器,就像什么都没有发生一样
这是从重置MySQL根密码。
我在mariadb的termux中遇到了这个问题,它解决了我的问题是以下两行命令-
Pkill MySQL
Mysqld_safe -u root
我用重启mysql解决了这个问题
/etc/init.d/mysql stop
and
/etc/init.d/mysql start
就是这样。
在我的情况下,似乎我不能真正杀死mysql进程,当我运行
sudo service mysql stop
ps -ef | grep mysql
mysql进程一直在那里,看起来它阻塞了套接字文件,新的mysql进程不能自己创建它。
这很有帮助
cd /var/run
sudo cp mysqld/ mysqld.bc -rf
sudo chown mysql:mysql mysqld.bc/
sudo service mysql stop
sudo cp mysqld.bc/ mysqld -rf
sudo chown mysql:mysql mysqld -R
sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking &
现在我能够登录数据库使用
mysql -u root
然后更新root密码:
UPDATE user SET authentication_string=password('YOURPASSWORDHERE') WHERE user='root';
FLUSH PRIVILEGES;
PS:我在更新根密码时遇到了麻烦,似乎是“auth_socket”插件的问题,所以我必须创建具有完整权限的新用户
insert into user set `Host` = "localhost", `User` = "super", `plugin` = "mysql_native_password", `authentication_string` = NULL, `password_expired` = "N", `password_lifetime` = NULL, `account_locked` = "N", `Select_priv` = "Y",
`Insert_priv` = "Y", `Update_priv` = "Y", `Delete_priv` = "Y", `Create_priv` = "Y", `Drop_priv` = "Y", `Reload_priv` = "Y", `Shutdown_priv` = "Y", `Process_priv` = "Y", `File_priv` = "Y",
`Grant_priv` = "Y", `References_priv` = "Y", `Index_priv` = "Y", `Alter_priv` = "Y", `Show_db_priv` = "Y", `Super_priv` = "Y", `Create_tmp_table_priv` = "Y", `Lock_tables_priv` = "Y",
`Execute_priv` = "Y", `Repl_slave_priv` = "Y", `Repl_client_priv` = "Y", `Create_view_priv` = "Y", `Show_view_priv` = "Y", `Create_routine_priv` = "Y", `Alter_routine_priv` = "Y",
`Create_user_priv` = "Y", `Event_priv` = "Y", `Trigger_priv` = "Y", `Create_tablespace_priv` = "Y";
这将创建一个没有密码的用户“super”,然后你可以连接mysql -u super
我只是在不得不重新启动生产服务器后遇到了同样的问题。我正在DigitalOcean液滴上运行Debian 8.1 (Jessie)。
这是我解决问题的方法:
检查文件/var/run/mysqld/mysqld.袜子的存在。如果没有,手动创建它,输入touch /var/run/mysqld/mysqld.袜子(这是我必须做的)。 所以MySQL进程可以使用这个文件。通过输入chown mysql /var/run/mysqld/mysqld.sock更改该文件的所有权。 执行完“2”后,输入service MySQL restart或/etc/init.重新启动MySQL服务d / mysql重启。
经过上述步骤后,我的问题得到了解决。我很少遇到这种问题,可能有更好的方法,所以如果需要,请务必提供建设性的反馈:)。