我在Ubuntu 12.04 LTS (Precise穿山甲)上安装了LAMP,然后在phpMyAdmin上设置根密码。我忘记密码了,现在无法登录。当我试图通过终端更改密码时,我得到:

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

我该如何解决这个问题?我无法打开LAMP,卸载它或重新安装它。


当前回答

打开终端,输入:

sudo apt-get purge mysql-client-core-5.6

sudo apt-get autoremove

sudo apt-get autoclean

sudo apt-get install mysql-client-core-5.5

sudo apt-get install mysql-server  

MySQL数据库核心客户端和MySQL服务器包将是相同的5.5版本。MySQL Client 5.5和MySQL Server 5.5是Ubuntu 14.04中这些包的当前“最佳”版本,由包维护者决定。

如果你想安装MySQL Client 5.6和MySQL Server 5.6,你也可以在Ubuntu软件中心找到MySQL - Client -core-5.6和MySQL - Server -5.6包。重要的是客户端和服务器版本号在两种情况下都要匹配。

这对我很管用。

其他回答

我的服务器存储空间已满,导致Mysql无法启动。从这里得到了灵感。增加高清和重新启动修复了这个问题。

MySQL服务器进程没有创建套接字,或者客户端在错误的地方寻找套接字。

我的第一个建议是检查MySQL服务器是否正在运行。第二个建议可能是,MySQL服务器是否运行在另一个主机上?如果是这样,在终端的MySQL客户端中添加-h <hostname>标志。

如果MySQL确实在运行,并且在本地运行,请检查my.cnf文件。应该有这样的线条

socket = /var/run/mysqld/mysqld.sock

看看是否与你在文章中提到的套接字位置相匹配。

根据经验,我想说最可能的情况是你的MySQL服务器根本没有运行,或者与你在终端上运行MySQL客户端不在同一台主机上运行。

将/opt/lampp/etc/my.cnf文件复制到/etc/mysql/my.cnf

在终端类型中:

mysql -u root

你会得到mysql>提示:

mysql> Update mysql.user set Password=PASSWORD('your_password') where user='root';

mysql> FLUSH PRIVILEGES;

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.

这个答案与在内存较小的机器上更新到MySQL 5.6有关

我在Debian 8 (Jessie)上从MySQL 5.5升级到5.6时遇到了同样的问题。MySQL没有启动(状态显示为active/exited),简单地让服务MySQL启动不起作用,因为我从/var/logs/ MySQL /error.log日志文件中发现:

InnoDB: Initializing buffer pool, size = 128.0M
InnoDB: mmap(136019968 bytes) failed; errno 12
Cannot allocate memory for the buffer pool

内存不够:我只有256 MB的RAM。

在MySQL中有一个设置,performance_schema。默认情况下,它在MySQL 5.5中是关闭的。

https://dev.mysql.com/doc/refman/5.5/en/performance-schema-startup-configuration.html

但在MySQL 5.6中,默认是开启的,只需在/etc/mysql/my.cnf文件中添加以下一行并重新启动,就可以工作了。

performance_schema = off

警告:关闭此设置可能会遇到性能问题,但我猜在开发环境中这不会是问题。

此外,这里有一篇文章,可能有助于配置MySQL使用最小内存,配置MySQL使用最小内存(web存档链接,以防原来的链接在未来过期https://web.archive.org/web/20201112041608/http://www.tocker.ca/2014/03/10/configuring-mysql-to-use-minimal-memory.html)。