RHEL7/Mysql create new DB and new user, grant privileges

lake@localhost:~$ mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 26
Server version: 5.5.44-MariaDB MariaDB Server

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

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

MariaDB [(none)]> create user 'training'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.00 sec)

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

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
 

MariaDB [mysql]> select host,user from user;
+-----------+----------+
| host      | user     |
+-----------+----------+
| 127.0.0.1 | root     |
| ::1       | root     |
| localhost | discuz   |
| localhost | root     |
| localhost | test     |
| localhost | training |
+-----------+----------+
6 rows in set (0.00 sec)

##########create new DB training 

create database training DEFAULT CHARSET utf8 COLLATE utf8_general_ci;

##########


MariaDB [(none)]> grant all privileges on `training`.* to 'training'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.00 sec)

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

MariaDB [(none)]> exit
Bye


lake@localhost:~$ mysql -u training -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'training'@'localhost' (using password: YES)
lake@localhost:~$ mysql -u training -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 30
Server version: 5.5.44-MariaDB MariaDB Server

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

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

MariaDB [(none)]> use  training
Database changed
 
MariaDB [training]>  show tables
    -> ;
Empty set (0.00 sec)

MariaDB [training]> 
 

MariaDB [training]> show grants;  
+-----------------------------------------------------------------------------------------------------------------+
| Grants for training@localhost                                                                                   |
+-----------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'training'@'localhost' IDENTIFIED BY PASSWORD '*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9' |
| GRANT ALL PRIVILEGES ON `training`.* TO 'training'@'localhost'                                                  |
+-----------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

MariaDB [training]> 
 

 

########## grant and revoke 

lake@localhost:~$ mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 26
Server version: 5.5.44-MariaDB MariaDB Server

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

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

 

MariaDB [(none)]> grant all privileges on `training`.* to 'test'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.00 sec)

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

MariaDB [(none)]> show grants for test@localhost;
+-------------------------------------------------------------------------------------------------------------+
| Grants for test@localhost                                                                                   |
+-------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'test'@'localhost' IDENTIFIED BY PASSWORD '*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9' |
| GRANT ALL PRIVILEGES ON `training`.* TO 'test'@'localhost'                                                  |
+-------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
 

MariaDB [(none)]> quit
Bye
 

## try test on DB training 

lake@localhost:~$ mysql -u test -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 82
Server version: 5.5.44-MariaDB MariaDB Server

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

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

MariaDB [(none)]> select host,user from user;
ERROR 1046 (3D000): No database selected
MariaDB [(none)]> use training 
Database changed
MariaDB [training]> show tables
    -> ;
Empty set (0.00 sec)

MariaDB [training]> quit
Bye
 

 

#### rework test on DB training ..  

lake@localhost:~$ mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 26
Server version: 5.5.44-MariaDB MariaDB Server

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

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

MariaDB [(none)]> revoke  all privileges on `training`.* from 'test'@'localhost' ;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> show grants for test@localhost;
+-------------------------------------------------------------------------------------------------------------+
| Grants for test@localhost                                                                                   |
+-------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'test'@'localhost' IDENTIFIED BY PASSWORD '*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9' |
+-------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

MariaDB [(none)]> 
 

MariaDB [(none)]> quit
Bye
lake@localhost:~$ mysql -u test -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 86
Server version: 5.5.44-MariaDB MariaDB Server

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

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

MariaDB [(none)]> use training 
ERROR 1044 (42000): Access denied for user 'test'@'localhost' to database 'training'
MariaDB [(none)]> 
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章