MySQL – Creating a new user

It’s funny how you forget the simple things when you haven’t done them in a while.

Tonight I wanted to setup MySQL on my Windows 7 machine. The installation was simple and I happily had my root account created. However, I didn’t want to use my root account for development – mainly because I didn’t want the password to be sorted in clear text.

In order to create a new user, I used the command line MySQL client tool which allows me to execute commands against the server. You enter this via the command.

mysql --user="root" ––password

This will then prompt you for the root password. I could have entered this on the command line as well, but again it would be in the clear.

From the tool, I enter the following two commands. The first creates the user, the second assigns permissions.

CREATE USER 'new_username'@'localhost' IDENTIFIED BY 'password';

GRANT ALL ON *.* TO 'new_username'@'localhost';

I can then happily use this new user with my application. I wanted to post this in case anyone else keeps forgetting like me…