MySQL User management and Rights management

Source: Internet
Author: User

MySQL Default has a root user, but this user rights are too large, generally only in the management of the database when used. If you are connecting to a MySQL database in your project, it is recommended that you create a new user with a smaller permission to connect.

You can create a new user for MySQL by entering the following command in MySQL command line mode:

CREATE USER username identified by ' password ';

The new user is created, but at this point, if logged in as this user, 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 on * * to ' username ' @ ' localhost ' identified by ' password ';

Grant username all permissions to the user on all databases.

If you find that the permission you just gave is too large, if we just want to grant it permissions on a database, then we need to switch to the root user revoke the permissions just now, re-authorize:

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

You can even specify that the user can only execute select and update command:

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

This way, to username log in to MySQL again, only the wordpress database is visible to it, and if you only grant it select permission, then it cannot execute the delete statement.

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

FLUSH privileges;

Delete the user you just created:

DROP USER [email protected];

MySQL User management and Rights management

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.