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

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 |

 

标签:24,+--------------------+,1.0,sec,mysql,网段,root,localhost,centos8
来源: https://www.cnblogs.com/biaoming534/p/16536318.html