How to Grant Privileges in MySQL Database Server

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:

    [root@server ~]# 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 wp1user@localhost ;

5. Verify the grant access

    mysql> SHOW GRANTS FOR 'wp1user'@'localhost';
    | Grants for wp1user@localhost                                                          |
    | 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

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

A world leading hosting company that provides fully-managed innovative and secure solutions, suitable for hosting small to medium-sized websites

Built on the best available technologies combined with Google Cloud for strong redundancy and application availability. Backed by skilled experts to address web security threats, a devops team to create advanced custom security solutions, and 24/7 sysadmins to watch over the platform. This powerful, hands-on approach makes your sites faster, safer, and easier to manage. Starting from only $3.95/mo.


* up to 30 days money back guarantee