MySQL database four: Create user

Source: Internet
Author: User

NOTE: The SQL statement in the MySQL database is terminated by default with ";". Enter the command, the keyword can be uppercase or lowercase, but must be consistent, I prefer to use lowercase, personal habits bar.


There are three main ways of creating database users in MySQL:

1 by inserting data records into the user table of the MySQL library (note: MySQL users are saved by default in the user table):

mysql> INSERT INTO User (NAME,PASSWD) VALUES (' Zwj ', ' ABCDEFG ');

Description

INSERT INTO: keyword

User: Table name, followed by field name in parentheses

Values: keyword, followed by the value of the field in parentheses

The user can view the built user:mysql> select * from Mysql.user;

In general, it is not recommended to use the above method to create a user (too amateur)


2 Creating a user using the Create USER statement:

Mysql>create user ' t100 ' @ ' 127.0.0.1 ' identified by ' t100 ';

Description

Create User: Keyword

T100: User Name

127.0.0.1: Source address, which means this machine, can also be written as a network segment such as: 192.168.10.%

Identified by: The keyword used to set the password, if omitted, indicates that the password is empty

After the user is established, authorization is required, otherwise most operations will not work except to connect to the database.


3 Create a user and grant permissions by using the GRANT statement:

Mysql> Grant Select on mysql.* to ' t100 ' @ ' 192.168.10.1 ' identified by ' t100 ';

Description

Grant: Keyword

Select: Permissions for Queries

On: Keywords

All tables under the Mysql.*:mysql library, * as wildcards represent all

The above statement means setting up a user t110 that allows clients from 192.168.10.1 to access the database and grant permissions to the query.

The user needs to refresh the permissions table after it is built:

Mysql>flush privileges;

View Permissions:mysql> show grants for ' T100 ' @ ' 192.168.10.1 ';

Revoke permissions:mysql> Revoke select on mysql.* from ' t100 ' @ ' 192.168.10.1 ';

The third way is the more common way to create users and authorizations.

This article from "10,000 years too long, seize" blog, please be sure to keep this source http://zengwj1949.blog.51cto.com/10747365/1881481

MySQL database four: Create user

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.