2021-07-25

Mysql8.0在修改初始密码时出现的两个错误,1.ERROR 2003 (HY000): Can’t connect to MySQL server on ‘localhost:3306’ (10061) 2.ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘(‘123456’) where user=‘root’ and Host = ‘localhos’’ at line 1

问题1

我在最初的my.ini 文件中设置如下的

[mysqld]
basedir=D:\Program Files\mysql-5.7\
datadir=D:\Program Files\mysql-5.7\data\
port=3306
skip-grant-tables

按照正常的狂神的教程,当我首次在进入mysql -u root -p时出现了以下错误

E:\Enviorment\mysql-8.0.26-winx64\bin>mysql -u root -p
Enter password: 
ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost:3306' (10061)

解决方案

重新修改my.ini文件,将skip语句删除

[mysqld]
basedir=D:\Program Files\mysql-5.7\
datadir=D:\Program Files\mysql-5.7\data\
port=3306

再次运行mysql -u root -p

E:\Enviorment\mysql-8.0.26-winx64\bin>mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.26 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

成功进入。

问题2

当我继续执行修改初始密码的语句:update mysql.user set authentication_string=password('123456') where user='root' and Host = 'localhost';
出现以下错误:

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '('123456') where user='root' and Host = 'localhos'' at line 1

解决方案

将修改初始密码的语句修改为:

ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';一定注意分号 不能少

执行结果:

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.15 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.28 sec)

成功解决。

以上方案仅供参考,希望能有所帮助

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值