我在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,卸载它或重新安装它。
当前回答
如果您正在使用Amazon EC2,并且在实例上遇到了这个问题,那么您只需要执行以下操作:
sudo yum install mysql-server
sudo service mysqld restart
Amazon EC2没有安装服务器(只安装了客户端),因此在这种情况下,您需要在实例上安装服务器,然后尝试
mysql -u root -p
来检验这是否有效。
其他回答
您的mysql服务器可能没有运行。输入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.
我看到所有这些答案,但没有一个提供重置密码的选项,没有接受的答案。实际的问题是他忘记了密码,所以他需要重置,而不是像大多数答案所暗示的那样,看看它是否正在运行(安装与否)。
重置密码
遵循以下步骤(如果你真的忘记了密码,这可能会有帮助,你可以随时尝试,即使你现在没有这种情况):
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根密码。
我也遇到了同样的问题,问题是mysql服务器已经安装,但它没有运行。
试, 启动mysql服务 或 启动mysql
我的服务器存储空间已满,导致Mysql无法启动。从这里得到了灵感。增加高清和重新启动修复了这个问题。