【就业班作业】【第十四周】数据库授权magedu用户,允许192.168.1.0/24网段可以连接mysql

【第十四周】数据库授权magedu用户,允许192.168.1.0/24网段可以连接mysql

MariaDB [(none)]> use mysql
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
MariaDB [mysql]> create user 'magedu'@'192.168.0.%';
Query OK, 0 rows affected (0.01 sec)

MariaDB [mysql]> select authentication_string,password,user,host from user;
+-------------------------------------------+-------------------------------------------+--------+-------------+
| authentication_string                     | password                                  | user   | host        |
+-------------------------------------------+-------------------------------------------+--------+-------------+
|                                           | *3CD53EE62F8F7439157DF288B55772A2CA36E60C | root   | localhost   |
| *3CD53EE62F8F7439157DF288B55772A2CA36E60C | *128977E278358FF80A246B5046F51043A2B1FCED | root   | 127.0.0.1   |
| *3CD53EE62F8F7439157DF288B55772A2CA36E60C | *128977E278358FF80A246B5046F51043A2B1FCED | root   | ::1         |
|                                           |                                           | magedu | 192.168.0.% |
+-------------------------------------------+-------------------------------------------+--------+-------------+
4 rows in set (0.00 sec)

MariaDB [mysql]> update user set password=password('ubuntu') where user='magedu';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

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

MariaDB [mysql]> select authentication_string,password,user,host from user;
+-------------------------------------------+-------------------------------------------+--------+-------------+
| authentication_string                     | password                                  | user   | host        |
+-------------------------------------------+-------------------------------------------+--------+-------------+
|                                           | *3CD53EE62F8F7439157DF288B55772A2CA36E60C | root   | localhost   |
| *3CD53EE62F8F7439157DF288B55772A2CA36E60C | *128977E278358FF80A246B5046F51043A2B1FCED | root   | 127.0.0.1   |
| *3CD53EE62F8F7439157DF288B55772A2CA36E60C | *128977E278358FF80A246B5046F51043A2B1FCED | root   | ::1         |
|                                           | *3CD53EE62F8F7439157DF288B55772A2CA36E60C | magedu | 192.168.0.% |
+-------------------------------------------+-------------------------------------------+--------+-------------+
4 rows in set (0.00 sec)

MariaDB [mysql]> 

ps :授权访问hellodb库的所有权限

MariaDB [mysql]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| hellodb            |
| mysql              |
| performance_schema |
+--------------------+
4 rows in set (0.00 sec)

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

MariaDB [mysql]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| hellodb            |
| mysql              |
| performance_schema |
+--------------------+
4 rows in set (0.00 sec)

MariaDB [mysql]> show grants for 'magedu'@'192.168.0.%';
+-----------------------------------------------------------------------------------------------------------------+
| Grants for magedu@192.168.0.%                                                                                   |
+-----------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'magedu'@'192.168.0.%' IDENTIFIED BY PASSWORD '*3CD53EE62F8F7439157DF288B55772A2CA36E60C' |
| GRANT ALL PRIVILEGES ON `hellodb`.* TO 'magedu'@'192.168.0.%'                                                   |
+-----------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

MariaDB [mysql]> 

测试效果:

[root@centos7-node0 ~]# \mysql -umagedu -pubuntu -h192.168.0.106
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 35
Server version: 5.5.68-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 
MariaDB [(none)]> 
MariaDB [(none)]> 
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
+--------------------+
1 row in set (0.02 sec)

MariaDB [(none)]> 
MariaDB [(none)]> 
MariaDB [(none)]> 
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| hellodb            |
+--------------------+
2 rows in set (0.01 sec)

MariaDB [(none)]> 
MariaDB [(none)]> 

(结束)

posted @ 2020-11-30 13:56  sankeya  阅读(173)  评论(0编辑  收藏  举报