The default user has root Super Administrator, to make a website, to connect MySQL to a user name and password, can not be root, prevent misoperation. MySQL service can run multiple libraries, so you need to give individual users some authorization, only need to have a database or a database of a table has permissions.
Grant all on . to ' user1 ' identified by ' passwd '; Grant is authorized to mean all of the
1.mysql> Grant all in . to ' user1 ' @ ' 127.0.0.1 ' identified by ' 123 '; Authorized User1 can only log on to the MySQL (source IP) identified by password via 127 of this IP . The previous one represents the library name, followed by the table. IP can also use% to represent all IPs,
Query OK, 0 rows affected (0.63 sec)
2.[[email protected] ~]# mysql-uuser1-p123-h127.0.0.1//user login. If the authorized IP is localhost then you can use the-h
3.mysql> Grant all on db1.* to ' user1 ' @ ' 192.168.222.% ' identified by ' 1 ';
4.[[email protected] ~]# mysql-uuser1-p1-h192.168.222.51
5.grant Select,update,insert on DB1. To ' user2 ' @ ' 192.168.133.1 ' identified by ' passwd ';
6.grant all on db1. To ' user3 ' @ '% ' of ' identified by ' passwd ';
7.show grants;//View Authorization for the current user
Mysql> Show grants; View permissions must be entered in the user to be queried
+-------------------------------------------------------------------------------+
| Grants for [email protected]% |
+-------------------------------------------------------------------------------+
| GRANT USAGE on . To ' user1 ' @ ' 192.168.222.% ' identified by PASSWORD <secret> |
| GRANT all privileges in db1
. * to ' user1 ' @ ' 192.168.222.% ' |
+-------------------------------------------------------------------------------+
2 rows in Set (0.00 sec)
Mysql> Select User ();
+----------------------+
| User () |
+----------------------+
| [Email protected] |
+----------------------+
1 row in Set (0.00 sec)
8.show grants for [email protected]; View authorization for a specified user
Mysql> Select User ();
+----------------+
| User () |
+----------------+
| [Email protected] |
+----------------+
1 row in Set (0.00 sec)
Mysql> Grant Select,update,insert on db1.* to ' User3 ' @ ' 192.168.222.% ' identified by ' 123456 ';
Query OK, 0 rows Affected (0.00 sec)
Mysql> Show grants for [email protected] ' 192.168.222.% ';
+-------------------------------------------------------------------------------------------------------------- ----+
| Grants for [email protected]% |
+-------------------------------------------------------------------------------------------------------------- ----+
| GRANT USAGE on . To ' User3 ' @ ' 192.168.222.% ' identified by PASSWORD '6bb4837eb74329105ee4568dda7dc67ed2ca2ad9 ' |
| GRANT SELECT, INSERT, UPDATE on db1
. To ' User3 ' @ ' 192.168.222.% ' |
+-------------------------------------------------------------------------------------------------------------- ----+
2 rows in Set (0.00 sec)
MySQL create user and authorize