4.数据库授权magedu用户,允许192.168.1.0/24网段可以连接mysql


4.数据库授权magedu用户,允许192.168.1.0/24网段可以连接mysql

第一台主机上:
[root@centos8-8 ~]# hostname -I
192.168.1.8

[root@centos8-8 ~]# mysql -uroot -pMmagedu0!

(root@localhost) [(none)]> use mysql;

(root@localhost) [mysql]> show databases;
+--------------------+
| Database |
+--------------------+
| db1 |
| hellodb |
| information_schema |
| mysql |
| performance_schema |
| sys |
| zabbix |
+--------------------+

(root@localhost) [mysql]>create user magedu@'192.168.1.%' identified by 'Mmagedu0!';

(root@localhost) [mysql]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

(root@localhost) [mysql]>exit


++++++++++++++++++++

第二台主机上:
[root@centos8-18 ~]# systemctl start mysqld

[root@centos8-18 ~]# hostname -I
192.168.1.18

[root@centos8-18 ~]# mysql -umagedu -pMmagedu0! -h192.168.1.8
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.26 Source distribution

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.

能连,看不到多少,得针对某个数据库授权才行
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
+--------------------+
1 row in set (0.01 sec)

 

 


第一台主机上授权:
[root@centos8-8 ~]# hostname -I
192.168.1.8
[root@centos8-8 ~]# mysql -uroot -pMmagedu0!

(root@localhost) [mysql]> grant all privileges on hellodb.* to 'magedu'@'192.168.1.%';
Query OK, 0 rows affected (0.00 sec)

(root@localhost) [mysql]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

 

 

第二台主机上再次登录:

[root@centos8-18 ~]# mysql -umagedu -pMmagedu0! -h192.168.1.8

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| hellodb |
| information_schema |
+--------------------+
2 rows in set (0.01 sec)

mysql> use hellodb;
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 tables;
+-------------------+
| Tables_in_hellodb |
+-------------------+
| classes |
| coc |
| courses |
| scores |
| students |
| teachers |
| toc |
+-------------------+
7 rows in set (0.00 sec)

mysql> select * from scores;
+----+-------+----------+-------+
| ID | StuID | CourseID | Score |
+----+-------+----------+-------+
| 1 | 1 | 2 | 77 |
| 2 | 1 | 6 | 93 |
| 3 | 2 | 2 | 47 |
| 4 | 2 | 5 | 97 |

 

posted @   惊起千层浪  阅读(177)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 25岁的心里话
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
点击右上角即可分享
微信分享提示