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)
成功解决。
以上方案仅供参考,希望能有所帮助