Summary of basic user and rights management methods in Mysql _mysql

Source: Internet
Author: User

MySQL defaults to a root user, but this user permission is too large, usually only in the management of the database to use. If you are connecting to a MySQL database in your project, it is recommended that you create a new user with a small permission to connect.

In the MySQL command line mode, enter the following command to create a new user for MySQL:

CREATE USER username identified by ' password ';

New user creation completed, but now if you log in with this user, it will be an error, because we have not assigned the appropriate permissions for this user, the command to assign permissions are as follows:

GRANT all privileges in *.* to ' username ' @ ' localhost ' identified by ' password ';

Grant the username user all permissions on all databases.

If you find that the permission just given is too large, if we just want to give it permission on a certain database, then we need to switch to the ROOT to revoke the right, and authorize again:

Evoke all privileges to *.* from ' username ' @ ' localhost ';
GRANT all privileges in wordpress.* to ' username ' @ ' localhost ' identified by ' password ';

You can even specify that the user can only perform the Select and update commands:

GRANT SELECT, UPDATE on wordpress.* to ' username ' @ ' localhost ' identified by ' password ';

In this way, once again login to MySQL with username, only the WordPress database is visible to it, and if you only authorize it SELECT permissions, then it can not execute the DELETE statement.

In addition, each time you adjust permissions, you typically need to refresh the permissions by executing the following statement:

FLUSH privileges;

Delete the user you just created:

DROP USER Username@localhost;

Careful with the above commands, you may find that you specify the host of the response (that is, the content after the @ symbol), whether authorized or revoked, because the above pass orders are actually operating on the user table in the MySQL database, and you can view the appropriate user and the corresponding host with the following command:

SELECT User, Host from user;

Of course, this table also contains many other things, such as user passwords, permission settings, and many other content, the operation of particular need to be careful.

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.