MySQL – create user / add user to database

MySQL Add User FAQ: How do I add a user to MySQL (i.e., how do I create a MySQL user account)?

MySQL add user – solution

Solution: Here’s an example of what I did recently to (a) create a new MySQL database and then (b) add a new MySQL user account to work with that database. As usual, the database name, username, and password have been changed.

First, from my Unix prompt, I log into my MySQL database with the mysql command line client:

unix> mysql -u root -p
(here I enter ‘my_root_password’ to get through the mysql prompt)
Next, I create my new MySQL database with the “create database” command:

mysql> create database my_database;
And now I create a MySQL user account, giving the user account all the priviliges it needs to “own” this database, with the MySQL grant command. Note that I assign both the username and password when I add this MySQL user:

ON my_database.*
TO ‘my_user’@’localhost’
IDENTIFIED BY ‘my_password’