MySQL create user and authorize

Source: Internet
Author: User
Tags mysql create mysql create user

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.