How to add a user and grant database on MySQL

MySQL, 2015-06-17 00:16:13 UTC

1. Create user

$ mysql -u root -p

Enter password:


mysql> create user name@localhost identified by 'write password';


2. Grant specific database to a user

mysql> GRANT ALL PRIVILEGES ON  database_name.* TO  name@localhost WITH GRANT OPTION ;
mysql> FLUSH PRIVILEGES;  

 

And if you want to see all of user accounts;

select user from mysql.user;

Share: