In previous guide, I described the procedure of creating a MySQL user and granting privileges with the help of VPSrobots. In this article, let’s see how to create a MySQL user and grant privileges with command line.

Log in MySQL

Tipically, root is the primary MySQL account by default when MySQL is installed. Type the command line below to Log in MySQL:

mysql -u root -p

Create a new user

Type the following command line to create new user:

CREATE USER ‘newuser’@’localhost’ IDENTIFIED BY ‘password’;

Please replace newuser with the name of user you are creating and localhost can be remained or changed any host from which the user will be accessing MySQL, {cd2fad9c63f026f0ed27787855422acc34af553b5211e4dace6918e57f14e9ff} means to allow all host. password is the password for database login with the new created user.

Grant privileges to MySQL user

To grant all privileges to a user, type the following command line:

GRANT ALL PRIVILEGES ON *.* TO ‘newuser’@’localhost’;

“.” represents the databse.table and replace newuser and localhost with the new created user and host. To grant a user all privileges to a specific database, type the following command line:

GRANT ALL PRIVILEGES ON database_name .* TO ‘newuser’@’localhost’;

The user has all privileges to all tables in the specific database. If you want to target the individual table, replace database_name.* with database_name.table_name.

Flush privileges

To take effect for saving changes, please type the command line below:

flush privileges


0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

three × 2 =

We use cookies in order to give you the best possible experience on our website. By continuing to use this site, you agree to our use of cookies.
Accept
Reject
Privacy Policy