Monday, June 18, 2012

Adding User Accounts in mysql

Sample create user command for Mysql


CREATE USER 'myUser'@'localhost' IDENTIFIED BY 'hello';
GRANT SELECT,INSERT,UPDATE,DELETE ON *.* TO 'myUser'@'localhost';

The first command is the CREATE USER where
  • myUser is the user name
  • localhost is where the database is
  • hello is the password
The next command is the Grant command containing the Mysql statements to be allowed, the the database/s to be granted and the user to assigned for the permission.
  • The assigned user is myUser
  • The user can use the commands SELECT,INSERT,UPDATE,DELETE on all databases in localhost
  • ON *.* means that the user can use all the granted commands
  • ON *DBname.* can be used to allow the user to use the commands on the database names DBname
After the CREATE USER command has been executed, the user can now use the new user name and password as arguments in running mysql. In this example, the user can type mysql -u myUser -p then type hello. However not all commands can be used by myUser unlike the root user.

Reference

Oracle (2012). Adding User accounts. http://dev.mysql.com/doc/refman/5.1/en/adding-users.html