手抄报 安全手抄报 手抄报内容 手抄报图片 英语手抄报 清明节手抄报 节约用水手抄报

connect to server at 'localhost' failed

时间:2024-10-21 00:04:16

1、先停止MySQL服务打开“系统偏好设置”,选择“MySQL”,在打开的对话框中点击“Stop MySQL Server”

connect to server at 'localhost' failed
connect to server at 'localhost' failed

2、打开终端,输入命令:sudo/usr/local/mysql/bin/mysqld_safe --user=mysql --skip-grant-tables --skip-networking &--skip-grant-tables:不启动grant-tables(授权表),跳过权限控制。--skip-networking :跳过TCP/IP协议,只在本机访问(这个选项不是必须的。可以不用)

connect to server at 'localhost' failed

3、保留开启mysqld_safe的终端,新建一个终端,输入命令:mysql此时我们就可以直接登录到MySQL服务了。

connect to server at 'localhost' failed

4、查询MySQL的用户信息,输入SQL命令:select host,user,authentication_string from user;这一步骤熟悉的人可以跳过,在mysql 5.7以前的版本,密码列的英文名是password,但是在5.7版本改成了authentication_string,这点是需要注意的。

connect to server at 'localhost' failed

5、我们只需要重置用户名为root的密码就可以,输入SQL命令:update user set authentication_string=PASSWORD('123456') where user='root' and host='localhost';

connect to server at 'localhost' failed

6、新设置用户或更改密码后需用flush privileges刷新MySQL的系统权限相关表,否则会出现拒绝访问,还有一种方法,就是重新启动mysql服务器,来使新设置生效

connect to server at 'localhost' failed

7、重启MySQL服务,打开终端,输入命令:mysql -uroot -p输入刚设置好的密码就能成功登录

connect to server at 'localhost' failed
© 手抄报圈