This howto outlines the steps to add a new user to MySQL, and grant the new user permissions on a specific database.
Run the MySQL client:
$ mysql -u root -p
You will be asked for a password. If you don’t have a password set, simply press enter when prompted.
Run the following command to create a new user:
CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'somepassword';
This creates a new user called ‘newuser’, with the password of ‘somepassword’. Change these as required. Using ‘localhost’ as the host value allows logins only from the same machine that MySQL is installed on.
If you need to set up permissions for this new user on a specific database run the following command:
GRANT ALL ON databasename.* TO 'newuser'@'localhost';
Flush the privileges to make sure the newly added user and permissions are ready to use:
Exit the MySQL client: