MySQL easy to explore (ii)----MySQL user operation

Source: Internet
Author: User

In the previous section we completed the installation of MySQL, now we will open the actual combat mode, complete some basic MySQL operation. This section is divided into several parts:

        • User New in MySQL
        • User removal in MySQL
        • User modification in MySQL
        • User view in MySQL

The following chapters of the content distribution are in accordance with this pattern of----additions and deletions, which is the nature of the database.

    1. New for users in MySQL: Didn't we create the root user? Why you need to create a user, for a simple reason, like Linux, Root, but still need to create other users, because root is too high, many operations we do not want all users have permission to execute. In fact, it is a privilege to control the role.

Let's take a look at the table structure of mysq.user (output from the command select * from Mysql.user\g because of too many properties)

           

You can see that there are many parameters, and Select_privilege is expressing the permissions of the query.

Add a new User: INSERT INTO Mysql.user (Host,user,password) VALUES ("localhost", "Libo", Password ("* * *"));

In the same way, we look through the command, we can find the new user we do not have any permissions, all permissions properties are N, that is not now we do not have any permissions on the database operation?

But if we use the new user to log in to MySQL at this time, we will prompt the error: "Error 1045 (28000): Access denied for user ' libo ' @ ' localhost ' (using Password:yes), Why is this? Since MySQL does not support hot start, we are not aware of this change when we create a new user or a user right, so we use flush privileges to load this permission change.

But after the landing can be found that we do not have the authority to operate the database, new or not.

LocalHost permissions problem: If we create a user, we set the first parameter is localhost, then we can only log in locally, remote can not use the user to log on, if you want to remotely login, then we can change this parameter to%.

User rights issues: How do I grant permissions to new users? The syntax is as follows:

Grant permissions on the database. * to User name @ login host identified by "password";

Experiment, we just created a new user Libo did not give any permissions, and now we want to provide some basic new permissions, then we can write:

Grant create on test.* to [e-mail protected] identified by "* * *";

Let's test again now to see if we can create a new table.

We now find that we have new permissions, but we do not have permission to delete them.

2. User Delete operation:

Syntax: (in fact, the same grammatical structure as normal table) Delete fromt mysq.user where user= "Libo";

3. User Modification Actions:

Syntax: Update mysq.user set host= "%" where user= "* * *";

4. User View operation:

Syntax: SELECT * from Mysql.user where user= "* * *";

MySQL easy to explore (ii)----MySQL user operation

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.