You are here

Adding MySQL Users from the Command Line

Here's how to add a a mysql user with a password, from the command line, then assign them privileges on one, but not all, databases.  This uses create, grant and show.  You can also revoke.

$ /usr/bin/mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
mysql>
mysql> create user 'some-user'@'localhost' identified by 'some-password';
Query OK, 0 rows affected (0.00 sec)
mysql> grant all on some-db.* to 'some-user'@'localhost';
Query OK, 0 rows affected (0.00 sec)
mysql> show grants for 'some-user'@'localhost';
+----------------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'some-user'@'localhost' IDENTIFIED BY PASSWORD '*scrambledpassword' | 
| GRANT ALL PRIVILEGES ON `some-db`.* TO 'some-user'@'localhost'                                                   | 
+----------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
mysql>