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 |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 25岁的心里话
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器