我在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,卸载它或重新安装它。
当前回答
我也有同样的问题。我找到了这个。
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.
解决方案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。
我在mariadb的termux中遇到了这个问题,它解决了我的问题是以下两行命令-
Pkill MySQL
Mysqld_safe -u root
如果你使用Ubuntu,这可能是特权的问题。
检查您的目录权限。在root组中是不够的,还可以在MySQL写入的目录上使用chmod(例如,/var/run/mysqld/用于创建mysqld. exe)。pid文件)。
这对我很有帮助。
我认为当你得到错误的时候
ERROR 2002 (HY000):无法通过套接字/var/lib/ MySQL / MySQL .sock连接到本地MySQL服务器
我建议你先检查一下mysql守护进程是否在运行…大多数情况下,默认情况下它不会运行。你可以通过/etc/init.检查d / mysqld的地位。
如果它没有运行,那么先启动它:
.../etc/init.d/mysqld start.
我打赌它会110%有效。