Example of how to create a local user and grant database permissions to mysql, mysql example
Preface
When installing mysql, you usually generate a Super User root, which many people will continue to use later. Although this will be very convenient, the super user permission is too large, using it in all places is usually a security risk.
This is similar to the user management of the operating system. Most people prefer to use administrator or root users for convenience. This is not recommended.
So, how do I create a user other than root in mysql and grant corresponding permissions?
Let's look at an example:
CREATE USER ‘golden‘@'localhost' IDENTIFIED BY ‘gd2017‘;GRANT ALL ON myapp.* TO ‘golden‘@'localhost';FLUSH PRIVILEGES;
For the preceding statements, the following is a simple explanation:
1. The create user statement is used to create a user (and password ).
Here, golden is the user name and gd2017 is the password. Localhost indicates a local user.
2. grant statements are used to grant permissions to users.
"All" indicates all permissions, including adding, deleting, modifying, and querying data and modifying databases. "myapp" indicates a specific database name, "myapp. * Indicates all tables (and views) in the database; golden indicates the username created just now.
3. Use the flush statement to make the change take effect.
Expansion:
Generally, the above settings can meet General requirements. For more detailed configuration, refer to the mysql official online documentation (version 5.7 ):
Https://dev.mysql.com/doc/refman/5.7/en/create-user.html
Https://dev.mysql.com/doc/refman/5.7/en/grant.html
Summary
The above is all the content of this article. I hope the content of this article will help you in your study or work. If you have any questions, please leave a message, thank you for your support.