How to Grant Privileges in MySQL Database Server

Share this Article :

In this tutorial, i will guide you how to grant privileges in MySQL database server. You must connect to the MySQL Server as a root user and perform below task:

1. How to Login MySQL DB as a root:

    [[email protected] ~]# mysql -u root -p
    Enter password:
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 214
    Server version: 5.0.77 Source distribution
    Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

2. How to Create MySQL Database : wp1db

    mysql> CREATE DATABASE wp1db;

3. How to Create user with password : wp1user /wp1password

    mysql> CREATE USER 'wp1user'@'localhost' IDENTIFIED BY 'wp1password';

4. How to Grant all privileges on wp1db to wp1user

    mysql> GRANT ALL PRIVILEGES ON wp1db.* to [email protected] ;

5. Verify the grant access

    mysql> SHOW GRANTS FOR 'wp1user'@'localhost';
    | Grants for [email protected]                                                          |
    | GRANT USAGE ON *.* TO 'wp1user'@'localhost' IDENTIFIED BY PASSWORD '67ca6cf16fbdbef2' |
    | GRANT ALL PRIVILEGES ON `wp1db`.* TO 'wp1user'@'localhost'                            |
    2 rows in set (0.00 sec)

Leave a Reply