C:\Users\Administrator>mysql -h 127.0.0.1 -uroot --port=3306 -p
Enter password: *****
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.6.17 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
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> exit
Bye
C:\Users\Administrator>mysql -h 127.0.0.1 -uroot --port=3308 -p
Enter password: *****
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.5.61 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
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> exit
Bye
C:\Users\Administrator>mysql -h 127.0.0.1 -uroot --port=3307 -p
Enter password: *****
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 16
Server version: 8.0.13 MySQL Community Server - GPL
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
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> exit
Bye
┌──(root㉿kali)-[~]
└─# mysql -h 69.45.123.1 -uroot --port=3307 -p
Enter password:
ERROR 1130 (HY000): Host '69.45.123.128' is not allowed to connect to this MySQL server
update mysql.user set authentication_string=password('新密码') where user='用户名' and Host ='localhost';
update mysql.user set authentication_string=password('admin') where user='用户名' and Host ='localhost';
C:\Users\Administrator>mysql -uroot -p -P3306
Enter password: *****
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.17 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
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> use mysql; # 使用数据库
Database changed
mysql> select user,password,host from user where user='root'; # 先查询下 有权限的 用户 的 host 是什么
+------+-------------------------------------------+-----------+
| user | password | host |
+------+-------------------------------------------+-----------+
| root | *4ACFE3202A5FF5CF467898FC58AAB1D615029441 | localhost |
| root | *4ACFE3202A5FF5CF467898FC58AAB1D615029441 | 127.0.0.1 |
| root | *4ACFE3202A5FF5CF467898FC58AAB1D615029441 | ::1 |
+------+-------------------------------------------+-----------+
3 rows in set (0.00 sec)
# 修改 "mysql" 数据库里的 "user" 表里的 "host" 项,从"localhost"改为"%"
mysql> update user set host = '%' where user = 'root' and host='localhost';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 0 Changed: 0 Warnings: 0
mysql> flush privileges; # 刷新一下 mysql的缓存
Query OK, 0 rows affected (0.00 sec)
mysql> use mysql; # 使用数据库
Database changed
mysql> update user set host = 'localhost' where user = 'root' and host='%';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 0 Changed: 0 Warnings: 0
mysql> flush privileges; # 刷新一下 mysql的缓存
Query OK, 0 rows affected (0.00 sec)
/*myuser mypassword 为对应的 用户迷宫和密码 */
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
如果你想允许用户myuser从ip为192.168.1.3的主机连接到mysql服务器,并使用mypassword作为密码
/*例如 */
GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.3' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.3' IDENTIFIED BY '1235' WITH GRANT OPTION;
mysql> flush privileges; # 刷新一下 mysql的缓存
Query OK, 0 rows affected (0.00 sec)
# 查看授权的所有用户
mysql> SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROM mysql.user;
+---------------------------+
| query |
+---------------------------+
| User: 'root'@'127.0.0.1'; |
| User: 'root'@'::1'; |
| User: ''@'localhost'; |
| User: 'root'@'localhost'; |
+---------------------------+
4 rows in set (0.00 sec)
# revoke all on *.* from 'username'@'%'; username为指定的用户,%为任意登录的地址。
mysql> revoke all on *.* from 'root'@'192.168.1.3';
Query OK, 0 rows affected (0.00 sec)
# 然后再次
mysql> flush privileges; # 刷新一下 mysql的缓存
Query OK, 0 rows affected (0.00 sec)