How to create a new user and grant permissions using the MySQL command line

Source: Internet
Author: User
Tags mysql command line

Can the MySQL command line implement a new user? The answer is undoubtedly yes. You can also grant permissions to a user after you create a new user using the MySQL command line.

First of all, to declare: In general, to modify the MySQL password, authorization, is required to have the root authority in MySQL.
Note: This operation is also available at the win command prompt, phpMyAdmin.
Users: Phplamp
User database: Phplampdb

1.MySQL command line New user

Log in to MySQL
@>mysql-u root-p
@> Password
Create user
mysql> INSERT INTO Mysql.user (Host,user,password) VALUES (' localhost ', ' phplamp ', Password (' 1234 '));
Refresh System Permissions Table
Mysql>flush Privileges;
This creates a user named: Phplamp with a password of: 1234.

Log in after exiting
mysql>exit;
@>mysql-u phplamp-p
@> Enter password
Mysql> Login Successful

2.MySQL Command Behavior User authorization

Log in to MySQL (with root privileges). I am logged in as root.
@>mysql-u root-p
@> Password
First create a database for the user (phplampdb)
Mysql>create database phplampdb;
Authorizing Phplamp users to have all rights to the Phplamp database
@>grant all privileges in phplampdb.* to [e-mail protected] identified by ' 1234 '; //You need to note that if you find that the user is not found, you need to execute the command flush privilieges;
Refresh System Permissions Table
Mysql>flush privileges;
Mysql> Other operations

If you want to specify partial permissions to a user, you can write:
Mysql>grant select,update on phplampdb.* to [e-mail protected] identified by ' 1234 ';
Refreshes the System permissions table.
Mysql>flush privileges;

Mysql> grant permissions 1, permissions 2,... Permission n on the database name. Table name to User name @ user address identified by ' connection password ';

Permissions 1, Permissions 2,... Permission n represents 14 permissions, such as Select,insert,update,delete,create,drop,index,alter,grant,references,reload,shutdown,process,file.
When permissions 1, permissions 2,... Permission n is replaced by all privileges or all to give the user full permission.
When the database name. The table name is replaced by *. *, which indicates that the user is given permission to manipulate all tables on the server.
The user address can be localhost, or it can be an IP address, a machine name, and a domain name. You can also use '% ' to indicate connections from any address.
' Connection password ' cannot be empty, otherwise the creation failed.

For example:
Mysql>grant Select,insert,update,delete,create,drop on Vtdc.employee to [e-mail protected] identified by ' 123′;
Assign the user Joe from 10.163.225.87 the ability to perform operations such as Select,insert,update,delete,create,drop on the employee table VTDC the database, and set the password to 123.

Mysql>grant all privileges in vtdc.* to [e-mail protected] identified by ' 123′;
For users from 10.163.225.87, Joe assigns permissions to all operations on the database VTDC all tables, and sets the password to 123.

Mysql>grant all privileges on * * to [e-mail protected] identified by ' 123′;
For users from 10.163.225.87, Joe assigns permissions to all the tables in all databases and sets the password to 123.

Mysql>grant all privileges on * * to [e-mail protected] identified by ' 123′;
Assign the native user Joe permission to all operations on all tables in all databases, and set the password to 123.

How to create a new user and grant permissions using the MySQL command line

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.