Linuxmysql creates a user and grants permissions _ MySQL

Source: Internet
Author: User
Create a user in linuxmysql and grant the permission to 

1. create a user
// Log on to MYSQL
# Mysql-u root-p
# Password
// Create a user
Mysql> insert into mysql. user (Host, User, Password) values ('localhost', 'lwd ', password ('lwd '));
// Refresh the system permission list
Mysql> flush privileges;
In this way, a user named: lwd password: lwd is created.
// Log on after exiting
Mysql> exit;
# Mysql-u lwd-p
# Enter the password
Mysql> logon successful
2. authorize the user
// Log on to MYSQL (with ROOT permission ). I log on as ROOT.
# Mysql-u root-p
# Password
// Create a database (lwdDB) for the user first)
Mysql> create database lwdDB;
// Authorize the lwd user to have all permissions for the lwd database
# Grant all privileges on lwdDB. * to lwd @ localhost identifiedby 'lwd ';
// Refresh the system permission list
Mysql> flush privileges;
Mysql> Other operations
// If you want to assign some permissions to a user, you can write as follows:
Mysql> grant select, update on lwdDB. * to lwd @ localhost identifiedby 'lwd ';
// Refresh the system permission table.
Mysql> flush privileges;
Mysql> grant permission 1, permission 2 ,... Permission n on database name. Table name to user name @ user address identified by 'connection password ';
Permission 1, permission 2 ,... Permission n indicates 14 permissions, including select, insert, update, delete, create, drop, index, alter, grant, references, reload, shutdown, process, and file.
When permission 1, permission 2 ,... Permission n is replaced by all privileges or all, indicating that all permissions are granted to the user.
The database name. The table name is replaced by *. *, which grants the user the permission to operate all the tables in all databases on the server.
The user address can be localhost, IP address, machine name, or domain name. You can also use '%' to connect from any address.
The 'connection password' cannot be blank; otherwise, creation fails.
For example:
Mysql> grant select, insert, update, delete, create, drop onvtdc. employee to lwd@10.163.225.87 identified by '123 ′;
Assign the user lwd from 10.163.225.87 the permission to perform select, insert, update, delete, create, drop and other operations on the employee table of the database vtdc, and set the password to 123.
Mysql> grant all privileges on vtdc. * to lwd@10.10.10.87 identifiedby '000000 ′;
Assign the user lwd from 10.163.225.87 the permission to perform all operations on all tables in the database vtdc and set the password to 123.
Mysql> grant all privileges on *. * to lwd@10.10.10.87 identifiedby '000000 ′;
Assign the user lwd from 10.163.225.87 the permission to perform all operations on all tables in all databases and set the password to 123.
Mysql> grant all privileges on *. * to lwd @ localhost identifiedby '000000 ′;
Assign the local user lwd the permission to perform all operations on all tables in all databases, and set the password to 123.
3. delete a user
# Mysql-u root-p
# Password
Mysql> delete from user WHERE User = "lwd" and Host = "localhost ";
Mysql> flush privileges;
// Delete the user's database
Mysql> drop database lwdDB;
4. change the password of a specified user
# Mysql-u root-p
# Password
Mysql> update mysql. user set password = password ('New password') whereUser = "lwd" and Host = "localhost ";
Mysql> flush privileges;
Mysql> quit;

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.