Sunday, September 23, 2012

Create MySQL user and database

I need to create new MySQL database and a user once in a while, and and I never quite remember the exact command how to do it.

So, a note to self, this is how to do it.

$ mysql -u adminusername -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5340 to server version: 3.23.54
 
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
 
mysql> CREATE DATABASE databasename;
Query OK, 1 row affected (0.00 sec)
 
mysql> GRANT ALL PRIVILEGES ON databasename.* TO "wordpressusername"@"hostname"
    -> IDENTIFIED BY "password";
Query OK, 0 rows affected (0.00 sec)
  
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)

mysql> EXIT
Bye
$ 
 
By the way, this is lifted from wordpress document, http://codex.wordpress.org/Installing_WordPress#Using_the_MySQL_Client

No comments:

Post a Comment