MySQL Setup: Initial Accounts and Databases

# Filed on by / reply

If you’ve just installed MySQL or are just using it for the first time, there are a few things that you need to do before using it in your applications.  All of these operations are done via the mysql command line client, so open a terminal and type:

mysql -u root

This should put you at a mysql prompt like this:

mysql> 

The first thing to do is set a password on the root account, for security purposes; having no password is highly insecure.  Type the following command, replacing secret with your new password, and leaving the quotes in place:

mysql> UPDATE mysql.user SET Password = PASSWORD('secret')
    -> WHERE User = 'root';

mysql> FLUSH PRIVILEGES;

Now type "exit" to quit the mysql client, then start it again like this:

mysql -u root -p

It will now prompt you for your password.

Second, you’ll want to delete the built-in anonymous access accounts:

mysql> DELETE FROM mysql.user WHERE User = '';

mysql> FLUSH PRIVILEGES;

Third, you need to create a database for your application(s) to use:

mysql> CREATE DATABASE mydb01;

Finally, you need to create a user account in MySQL for your application(s) to use (replace username and password with an actual username and a password:

mysql> GRANT ALL PRIVILEGES ON mydb01.* TO 'username'@'localhost'
    -> IDENTIFIED BY 'password';

mysql> GRANT ALL PRIVILEGES ON mydb01.* TO 'username'@'%'
    -> IDENTIFIED BY 'password';

Now type "exit" to quit the mysql client.

For more details, see the Post-Installation Setup and Testing section of the MySQL manual.



Reply to this message here:

Your name
Email (why?)
Website (if you have one)
Subject
search posts:

[ archives ]