我在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进程,当我运行
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
其他回答
在Ubuntu 18:10 Linode 1GB Ram中,我遇到了这个错误。在检查了/var/log/mysql/error.log之后,我发现了这个:
[注]InnoDB: innodb_empty_free_list_algorithm由于缓冲池大小较小,修改为legacy。为了使用回退,请将缓冲池至少增加到20MB。
我把我的linode升级到2GB,用sudo mysql重新启动mariadb。接下来运行mysql_secure_admin,但是没有为user-as ususl设置根密码,直到更改根用户使用mysql_native_password插件。 不确定,但似乎袜子是创建的,但由于我的VPS内存不足,服务器关闭了。
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.
我以前在Kubuntu 20.04中遇到过这个问题。我的解决办法就是跑:
sudo dpkg --configure -a
原因是dpkg崩溃了。
我以前也遇到过这个问题,我通过跑步解决了它:
sudo /etc/init.d/mysql start
我想服务停止了。
现在有用了……
我已经使用Homebrew在Mac OS X上安装MariaDB 10.1.16教程来解决这个问题。
但是不要忘记杀死或卸载MariaDB的旧安装。
MySQL服务器进程没有创建套接字,或者客户端在错误的地方寻找套接字。
我的第一个建议是检查MySQL服务器是否正在运行。第二个建议可能是,MySQL服务器是否运行在另一个主机上?如果是这样,在终端的MySQL客户端中添加-h <hostname>标志。
如果MySQL确实在运行,并且在本地运行,请检查my.cnf文件。应该有这样的线条
socket = /var/run/mysqld/mysqld.sock
看看是否与你在文章中提到的套接字位置相匹配。
根据经验,我想说最可能的情况是你的MySQL服务器根本没有运行,或者与你在终端上运行MySQL客户端不在同一台主机上运行。