Example of how to create a local user and grant database permissions to mysql, mysql example

Source: Internet
Author: User

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.

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.