Add a new user to the MySQL database

Source: Internet
Author: User

After MySQL is installed on VPS, the default user is root @ localhost. The simplest way to add a new MySQL User is:

Execute the following statement in phpmyadmin (add points at the end of the statement; no ):

Grant all privileges on DBNAME. * to USERNAME @ localhost identified by 'password'
Flush privileges

Of course, run in SSH

Mysql-uroot-p

Then, you can enter the preceding SQL statement, with the same effect.

Explanation:

This will add a new user with the USERNAME and PASSWORD. This user has the permission to modify and read the database DBNAME.

Add an idea to clarify how to add users

1. Create a user

Mysql-u root-p

Enter password

Then go to mysql command line management


Insert into mysql. user (Host, User, Password) values ('localhost', 'admin', password ('123 '));


// Refresh the system permission list

Mysql> flush privileges;


2. Create a database

Create database newdatabase;


3. Authorize the user

Mysql> grant all privileges on newdatabase. * to admin @ localhost identified by '123 ';
Mysql> flush privileges;


You can also grant specific permissions to this user.

Grant select, insert, update, delete on newdatabase. * to admin @ localhost identified by '123 ';


A total of 14 permissions are available: select, insert, update, delete, create, drop, index, alter, grant, references, reload, shutdown, process, and file.

Mysql> grant all privileges on vtdc. * to joe@10.163.225.87 identified by '2017 & prime ;;
Assign the user joe 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 joe@10.163.225.87 identified by '2017 & prime ;;
Assign the user joe 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 joe @ localhost identified by '2017 & prime ;;
Grant the local user joe the permission to perform all operations on all tables in all databases and set the password to 123.

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.