Tuesday, November 06, 2012

Remove or Add MySQL user

Removing a user

-- first, let's see if the user is listed 
mysql> select * from mysql.user;

 
-- now let's kill the guy 
mysql> show grants for 'idiot'@'localhost';
mysql> revoke all privileges, grant option from 'idiot'@'localhost';
mysql> drop user 'idiot'@'localhost';
 
Adding a user

-- allow user to connect to the server
mysql> grant usage on *.* to amarokuser@localhost identified by 'amarokpasswd';

-- allow user to connect to the server 
mysql> grant all privileges on amarokdb.* to amarokuser@localhost ; 

-- another option (run mysql client as root, enter on command line) 
-- allows access from any IP for 'user'
GRANT ALL ON *.* to user@'%' IDENTIFIED BY 'password';

-- test if everything is OK now
mysql -u amarokuser -p'amarokpasswd' amarokdb