Users and Permissions in MySQL
// March 24th, 2009 // No Comments » // Database, MySQL
The best way for creating users in MySQL is by using CREATE USER or GRANT statements. Another way is by manipulating MySQLs grant tables, but this is not recommended.
By default the superuser is root. A password must be specified for this. It is best if this is only used for superadmin purposes.
For new accounts you need to create two users with the same name. One is for access via localhost, the other remotely.
GRANT ALL PRIVILEGES ON *.* TO 'user'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'user'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
To remove a user, use
DROP USER user;
To Change a password, use:
SET PASSWORD FOR 'user'@'localhost' = PASSWORD('newpassword');
SET PASSWORD FOR 'user'@'%' = PASSWORD('newpassword');
