How Do I Grant Permissions on MySQL?

Open Terminal

mysql -u root {PRESS ENTER}

Login to MySQL with your username, in my case it’s root.

mysql> show grants for 'root'@'localhost';

+--------------------------------------------------------------+
| Grants for root@localhost                                                                           |
+--------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION   |
| GRANT ALL PRIVILEGES ON `database1`.* TO 'root'@'localhost'                  |
| GRANT ALL PRIVILEGES ON `database2`.* TO 'root'@'localhost'                  |
+--------------------------------------------------------------+
3 rows in set (0.00 sec)

View current privileges of my user (root) to databases installed in MySQL.

mysql> grant all on database1.* to 'root'@'localhost';
mysql> use database1;

Grant permissions to my user for a specific database (database1).

mysql> -u root -e"flush privileges";

Reset privileges. Done.

Back to Blog

Say Hello

You can reach me by email, I'd love to hear from you.