我在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,卸载它或重新安装它。
当前回答
对我来说,更新解决了这个问题:
在Ubuntu上:
sudo apt-get update
sudo apt-get upgrade
CentOS:
sudo yum update
其他回答
解决方案1 清除(或删除如果你想保留数据库)任何mysql包,重新重复安装:
sudo apt purge "mysql*"
-Autoremove包
sudo apt autoremove
-停止apparmor服务
sudo systemctl stop apparmor
-让apparmor放弃它的配置文件(我以为用stop就够了,但对我来说不是。systemctl不起作用)
sudo service apparmor teardown
重新安装mysql服务器
sudo apt install mysql-server
安装apparmor-utils,在apparmor中为mysql创建一个允许mysql运行的配置文件
sudo apt install apparmor-utils
检查mysql-server的状态(必须是Active(running))
sudo systemctl status mysql
在apparmor中生成mysql的配置文件
sudo aa-genprof mysql
在其他终端运行mysql(输入root密码)
mysql -u root -p
当apparmor在另一个终端生成配置文件时,在MySQL中执行-do操作
创建数据库中的食物
-切换到另一个终端,按“s”(提示说这是“扫描”)
-对你认为合适的apparmor的政策说“是”(我猜所有的mysql),说“是”按“a”允许
-按“f”完成apparmor配置文件
-重启apparmor服务
sudo systemctl start apparmor
检查一下你是否可以在其他终端上使用mysql
Mysql>exit
mysql -u root -p
如果一切正常,您可以从命令行使用mysql。
我也有同样的问题。我找到了这个。
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’
这是因为在启动MySQL客户端之前没有运行mysqld守护进程。文件/var/lib/mysql/mysql.在运行MySQL的第一个实例时,将自动创建sock。
修复:
首先启动MySQL守护进程,然后输入MySQL:
/etc/init.d/mysqld start
mysql
修改MySQL Root密码
默认情况下,MySQL数据库的root密码为空。从安全角度考虑,将MySQL根密码更改为新密码是一个好主意。
mysql> USE mysql;
mysql> UPDATE user SET Password=PASSWORD('newpassword') WHERE user='root';
mysql> FLUSH PRIVILEGES;
完成后,通过登录进行检查:
mysql -u root -p
Enter Password: <your new password>
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.
令人惊讶的是,这个问题的另一个原因是删除了/var/log/mariadb文件夹 这是我的情况后,我删除了这个日志文件夹。创建完成后,错误消失了。
MySQL服务器进程没有创建套接字,或者客户端在错误的地方寻找套接字。
我的第一个建议是检查MySQL服务器是否正在运行。第二个建议可能是,MySQL服务器是否运行在另一个主机上?如果是这样,在终端的MySQL客户端中添加-h <hostname>标志。
如果MySQL确实在运行,并且在本地运行,请检查my.cnf文件。应该有这样的线条
socket = /var/run/mysqld/mysqld.sock
看看是否与你在文章中提到的套接字位置相匹配。
根据经验,我想说最可能的情况是你的MySQL服务器根本没有运行,或者与你在终端上运行MySQL客户端不在同一台主机上运行。