How-to create a MySQL database and assign user privileges to it

Written by Ian Carnaghan · 29 sec read >

NOTE: Please note that this is done in the Command Line Interface.

  • First login to the mySql server using root.
    mysql -uroot -pROOT_PASSWORD

    Replace ROOT_PASSWORD with the password for the root user.

  • Once logged in we create a new database called TEST_DB replace with your database name
    create database TESTDB;
    Query OK, 1 row affected (0.00 sec)
  • We grant access privileges to user MYUSER to connect to the mysql server from localhost using the password MYPASSWORD
    grant usage on *.* to [email protected] identified by 'MYPASSWORD';
    Query OK, 0 rows affected (0.00 sec)
  • Now we grant all privileges to MYUSER on the database TESTDB
    grant all privileges on TESTDB.* to [email protected] ;
    Query OK, 0 rows affected (0.00 sec)
  • Type exit to log out
  • Now you can login to TESTDB using user MYUSER and password MYPASSWORD

Last Updated On March 23, 2018
Written by Ian Carnaghan
I am a software developer and online educator who likes to keep up with all the latest in technology. I also manage cloud infrastructure, continuous monitoring, DevOps processes, security, and continuous integration and deployment. Profile

Leave a Reply

Notify of