MySql 5.x create a user and authorize the user

Source: Internet
Author: User

Why do I want to talk about mysql 5? In previous versions, we can directly use INSERT to INSERT mysql users to mysql tables. After mysql5 is complete, we won't be able to do this, next I will introduce MySql 5. x. For details about how to create and authorize users, refer.

Add a connection user account in the mysql user table:

Here, do not directly use the INSERT statement to add user records. INSERT may occur:

ERROR 1364 (HY000): Field 'ssl _ cipher 'doesn' t have a default value ERROR. However, I did not see this error in earlier MYSQL versions, because tianyuan has been directly modifying the user table or directly using the INSERT statement. When I upgraded MYSQL to 5.1, this error may occur.

Method

1. Create a user.

The Code is as follows: Copy code

// Log on to MYSQL
@> Mysql-u root-p
@> Password
// Create a user
Mysql> insert into mysql. user (Host, User, Password) values ("localhost", "phplamp", password ("1234 "));
// Refresh the system permission list
Mysql> flush privileges;
In this way, a user named: phplamp password: 1234 is created.

Then log on.

Mysql> exit;
@> Mysql-u phplamp-p
@> Enter the password
Mysql> logon successful


We recommend that you use the GRANT statement for authorization. The statement is as follows:

The Code is as follows: Copy code

Grant usage on *. * TO 'username' @ 'localhost' identified by 'Password' with grant option;

Last sentence:

Replace "username" with the user name to be authorized, such as clientusr;

Replace "password" with the password set by clientusr;

4. Data Table Access Authorization

After the account is created, authorize the preceding common user to the data table. The default permissions of the connected user added in step 3 are "N" and must be authorized for the account in the db table, allow the user to access the dedicated database. Of course, the super user will not talk about it.

Use the following statement:

The Code is as follows: Copy code

Grant select, INSERT, UPDATE, DELETE, CREATE, drop on tablename. * TO 'username' @ 'localhost' identified by 'Password ';

The permissions in this statement are determined based on actual needs:

Replace "tablename" with the table name of the authorized data table

"Username" is the username authorized in step 2.

"Password" is the password set for Step 2 Authorized Users

This grants the SELECT, INSERT, UPDATE, DELETE, CAREATE, and DROP permissions to a data table.

5. Authorization to take effect. creation is complete.

One sentence: flush privileges;


3. delete a user.

The Code is as follows: Copy code

@> Mysql-u root-p
@> Password
Mysql> delete from user WHERE User = "phplamp" and Host = "localhost ";
Mysql> flush privileges;
// Delete the user's database
Mysql> drop database phplampDB;

Related Article

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.