Setting up users

From Hashmysql
Jump to: navigation, search

When you first run install MySQL you will already have a user root which can log on without any password.

First off, create a second super user with full privileges but with a password

Grant all privileges on *.* to 'admin'@'localhost' identified by 'mypassword' with grant option;

Check you can log in with that and then set the password for root.

set password for 'root'@'localhost'= password('mypassword');

Don't leave the password() bit out. If you do it may just produce an error but it may set that value directly as the password without first encrypting it. When you log on it will encrypt the password you give and then compare it with the unencrypted version of the password which will be different. If you should ever do this to your root user (and have not set up a second super user ) then you need to check out Resetting Root.


Now set up a ordinary user:

Grant usage on *.* to 'FredBlogs'@'localhost' identified by 'Fredspass';

This just sets up and account that can only log in - which allows you to be specific about what it can do. So lets give Fred the right to mess with a specific database:

grant all privileges on newbase.* to 'Fredblogs'@'localhost';

And just in case you want to check on how many users you have set up then, as root, type:

use mysql;
select * from user;

(Mysql is just a database like any other but it is an an extreeemly bad idea to change it directly.)