SQL User DB Management

From Kb

Jump to: navigation, search

To add a user and a database do this and then flush the tables or do a mysqladmin reload.

db table


 insert into db (Host, Db, User, Select_priv, Insert_priv, Update_priv, Delete_priv, Create_priv, Drop_priv, Index_priv, Alter_priv)
 values ('localhost', 'database', 'user', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y','Y');


user table


 insert into user (Host, User, Password)
 values ('localhost', 'user', password('a1b2c3'));
 Select_priv, Insert_priv, Update_priv, Delete_priv, Create_priv, Drop_priv, Reload_priv, Shutdown_priv, Process_priv, File_priv, Grant_priv, References_priv, Index_priv, Alter_priv
UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='youruser';
FLUSH PRIVILEGES;

The quick way to do it:

GRANT ALL ON database.* TO 'username'@'localhost' IDENTIFIED BY 'password';

The GRANT command creates the entries in user and db tables for you.