mySQL Initial Config

Posted in How Did I Do That?

If you have never set a root password for MySQL server, the server does not require a password at all for connecting as root. To setup root password for first time, use mysqladmin command at shell prompt as follows:

$ mysqladmin -u root password NEWPASSWORD

However, if you want to change (or update) a root password, then you need to use the following command:

$ mysqladmin -u root -p'oldpw' password 'newpw'

 Now start the mysql client:

mysql -u root -p

 It will now prompt you for your password.

 Next, delete the built-in anonymous access accounts:

DELETE FROM mysql.user WHERE User = '';
FLUSH PRIVILEGES;

You need to create a database for your application(s) to use:

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.