以下是解决问题的过程:没整理
[root@localhost ~]# flush privileges;
bash: flush: 未找到命令…
[root@localhost ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 33
Server version: 8.0.28 MySQL Community Server - GPL
Copyright © 2000, 2022, 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.
mysql> flush privileges;
Query OK, 0 rows affected (0.08 sec)
mysql> select user, authentication_string, host from user;
ERROR 1046 (3D000): No database selected
mysql> select user, authentication_string, host from user;
ERROR 1046 (3D000): No database selected
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show databases;
±-------------------+
| Database |
±-------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
±-------------------+
4 rows in set (0.00 sec)
mysql> select user, authentication_string, host from user;
±-----------------±-----------------------------------------------------------------------±----------+
| user | authentication_string | host |
±-----------------±-----------------------------------------------------------------------±----------+
| mysql.infoschema | $A 005 005 005THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | localhost |
| mysql.session | $A 005 005 005THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | localhost |
| mysql.sys | $A 005 005 005THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | localhost |
| root | $A$005$3hlc7Dz0J>k_k#k90AQvZfa55jO5D.7B/8xl/NWXoxcJzClbsM0COL1s. | localhost |
±-----------------±-----------------------------------------------------------------------±----------+
4 rows in set (0.00 sec)
mysql> grant all privileges on . to ‘root’@‘192.168.62.129’ identified by ‘111111’ with grant option;
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 ‘identified by ‘111111’ with grant option’ at line 1
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> select user, authentication_string, host from user;
±-----------------±-----------------------------------------------------------------------±----------+
| user | authentication_string | host |
±-----------------±-----------------------------------------------------------------------±----------+
| mysql.infoschema | $A 005 005 005THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | localhost |
| mysql.session | $A 005 005 005THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | localhost |
| mysql.sys | $A 005 005 005THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | localhost |
| root | $A$005$3hlc7Dz0J>k_k#k90AQvZfa55jO5D.7B/8xl/NWXoxcJzClbsM0COL1s. | localhost |
±-----------------±-----------------------------------------------------------------------±----------+
4 rows in set (0.00 sec)
mysql> use mysql;//回车
Database changed
-> ;
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 ‘//回车’ at line 1
mysql> use mysql;
Database changed
mysql> select user,host from user;
±-----------------±----------+
| user | host |
±-----------------±----------+
| mysql.infoschema | localhost |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
±-----------------±----------+
4 rows in set (0.00 sec)
mysql> grant all privileges on . to ‘用户名’@‘192.168.1.1’ identified by ';
[1]+ 已停止 mysql -uroot -p
[root@localhost ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 34
Server version: 8.0.28 MySQL Community Server - GPL
Copyright © 2000, 2022, 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.
mysql> select User,Host from mysql.user;
±-----------------±----------+
| User | Host |
±-----------------±----------+
| mysql.infoschema | localhost |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
±-----------------±----------+
4 rows in set (0.00 sec)
mysql> grant all privileges on . to ‘用户名’@‘192.168.62.129’ identified by ‘111111’;
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 ‘identified by ‘111111’’ at line 1
mysql> ^C
mysql> ^C
mysql> check the manual that corresponds to your MySQL server version for the right syntax to use near ‘identified by ‘111111’’ at line 1
-> ;
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 ‘the manual that corresponds to your MySQL server version for the right syntax to’ at line 1
mysql> update user set host = ‘%’ where user =‘root’;
ERROR 1046 (3D000): No database selected
mysql> select User,Host from mysql.user;
±-----------------±----------+
| User | Host |
±-----------------±----------+
| mysql.infoschema | localhost |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
±-----------------±----------+
4 rows in set (0.00 sec)
mysql> update user set host = ‘%’ where user =‘root’;
ERROR 1046 (3D000): No database selected
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> use mysql;
Database changed
mysql> select Host,User from user;
±----------±-----------------+
| Host | User |
±----------±-----------------+
| localhost | mysql.infoschema |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
±----------±-----------------+
4 rows in set (0.00 sec)
mysql> update user set Host = ‘%’ where Host = ‘localhost’ & user = ‘root’;
ERROR 1292 (22007): Truncated incorrect DOUBLE value: ‘localhost’
mysql> GRANT ALL PRIVILEGES ON . TO ‘root’@‘%’ IDENTIFIED BY ‘111111’ WITH GRANT OPTION;
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 ‘IDENTIFIED BY ‘111111’ WITH GRANT OPTION’ at line 1
mysql> update user set Host = %
where Host = localhost
& user = root
;
ERROR 1054 (42S22): Unknown column ‘localhost’ in ‘where clause’
mysql> update user set Host = ‘%’ where Host = ‘localhost’ & user = ‘root’;
ERROR 1292 (22007): Truncated incorrect DOUBLE value: ‘localhost’
mysql> SELECT version();
±----------+
| version() |
±----------+
| 8.0.28 |
±----------+
1 row in set (0.00 sec)
mysql> create user test@‘localhost’ identified by ‘123456’;
Query OK, 0 rows affected (0.13 sec)
mysql> grant all privileges on test.* to test@‘localhost’;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql> grant all privileges on test.* to test@‘%’ identified by ‘123456’;
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 ‘identified by ‘123456’’ at line 1
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> update user set Host = ‘%’ where Host = ‘localhost’ & user = ‘root’;
ERROR 1292 (22007): Truncated incorrect DOUBLE value: ‘localhost’
mysql> GRANT ALL PRIVILEGES ON . TO ‘test’@‘%’ IDENTIFIED BY ‘123456’ WITH GRANT OPTION;
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 ‘IDENTIFIED BY ‘123456’ WITH GRANT OPTION’ at line 1
mysql> select Host,User from user;
±----------±-----------------+
| Host | User |
±----------±-----------------+
| localhost | mysql.infoschema |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
| localhost | test |
±----------±-----------------+
5 rows in set (0.00 sec)
mysql> create user test@‘localhost’ identified by ‘123456’;
ERROR 1396 (HY000): Operation CREATE USER failed for ‘test’@‘localhost’
mysql> create user test@‘localhost’ identified by ‘123456’;
ERROR 1396 (HY000): Operation CREATE USER failed for ‘test’@‘localhost’
mysql> create user itcast@‘%’ identified by ‘222222’;
Query OK, 0 rows affected (0.01 sec)
mysql> grant all privileges on itcast.* to itcast@‘%’;
Query OK, 0 rows affected (0.08 sec)
mysql> select Host,User from user;
±----------±-----------------+
| Host | User |
±----------±-----------------+
| % | itcast |
| localhost | mysql.infoschema |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
| localhost | test |
±----------±-----------------+
6 rows in set (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> select host,user,plugin,authentication_string from mysql.user;
±----------±-----------------±----------------------±-----------------------------------------------------------------------+
| host | user | plugin | authentication_string |
±----------±-----------------±----------------------±-----------------------------------------------------------------------+
| % | itcast | caching_sha2_password | $A 005 005 005E]>~ndZ’5+2y
bztXwIdm0hkP1cuQNStKwz/RRyyxvcV2cNlW316qAZ4x. |
| localhost | mysql.infoschema | caching_sha2_password | $A 005 005 005THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | mysql.session | caching_sha2_password | $A 005 005 005THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | mysql.sys | caching_sha2_password | $A 005 005 005THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | root | caching_sha2_password | $A$005$3hlc7Dz0J>k_k#k90AQvZfa55jO5D.7B/8xl/NWXoxcJzClbsM0COL1s. |
| localhost | test | caching_sha2_password | $A 005 005 005’\f
b4Cj*4:7ZJitBtLWRd4.xSYhW0lJdxmmIbcx4rpv6DSKuIB8VE02 |
±----------±-----------------±----------------------±-----------------------------------------------------------------------+
6 rows in set (0.00 sec)
mysql> ALTER USER ‘itcast’@‘%’ IDENTIFIED WITH mysql_native_password BY ‘222222’;
Query OK, 0 rows affected (0.10 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql> create user itcast@‘%’ identified by ‘222222’;
ERROR 1396 (HY000): Operation CREATE USER failed for ‘itcast’@‘%’
mysql> alter user root@‘%’ identifiedd by ‘111111’;
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 ‘identifiedd by ‘111111’’ at line 1
mysql> create user root@‘%’ identified by ‘111111’;
Query OK, 0 rows affected (0.00 sec)
mysql> grant all privileges on root.* to root@‘%’;
Query OK, 0 rows affected (0.00 sec)
mysql> select Host,User from user;
±----------±-----------------+
| Host | User |
±----------±-----------------+
| % | itcast |
| % | root |
| localhost | mysql.infoschema |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
| localhost | test |
±----------±-----------------+
7 rows in set (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql> select host,user,plugin,authentication_string from mysql.user;
±----------±-----------------±----------------------±-----------------------------------------------------------------------+
| host | user | plugin | authentication_string |
±----------±-----------------±----------------------±-----------------------------------------------------------------------+
| % | itcast | mysql_native_password | A0C1808B1A47CECD5C161FEE647F5427F4EB6F98 |
| % | root | caching_sha2_password | $A 005 005 005 MX.zybL:]%+(|g_SAG04DAeHUQ3nYTI4layGtJ9IZ20fLtmFMIxvyU86IA |
| localhost | mysql.infoschema | caching_sha2_password | $A 005 005 005THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | mysql.session | caching_sha2_password | $A 005 005 005THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | mysql.sys | caching_sha2_password | $A 005 005 005THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | root | caching_sha2_password | $A$005$3hlc7Dz0J>k_k#k90AQvZfa55jO5D.7B/8xl/NWXoxcJzClbsM0COL1s. |
| localhost | test | caching_sha2_password | $A 005 005 005’\f
b4Cj4:7ZJitBtLWRd4.xSYhW0lJdxmmIbcx4rpv6DSKuIB8VE02 |
±----------±-----------------±----------------------±-----------------------------------------------------------------------+
7 rows in set (0.00 sec)
mysql> IED WITH mysql_native_password BY ‘222222’;
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 ‘IED WITH mysql_native_password BY ‘222222’’ at line 1
mysql> alter user ‘root’@‘%’ identified with mysql_native_password by ‘111111’;
Query OK, 0 rows affected (0.00 sec)
mysql> grant all privileges on . to root@‘%’;
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql>
连接断开
连接主机…
连接主机成功
Last login: Tue Dec 20 09:47:19 2022 from 192.168.62.127
[root@localhost ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 48
Server version: 8.0.28 MySQL Community Server - GPL
Copyright © 2000, 2022, 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.
mysql> show databases
-> ;
±-------------------+
| Database |
±-------------------+
| information_schema |
| mysql |
| performance_schema |
| qq |
| sys |
±-------------------+
5 rows in set (0.03 sec)