ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

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

2022-07-31 02:01:38  阅读:195  来源: 互联网

标签:24 +--------------------+ 1.0 sec mysql 网段 root localhost centos8



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

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有