MySQL Cheat Sheet: Helpful MySQL Commands For Handling Databases, Users, and Privileges

There are many commands in MySQL that web developers will use on a frequent basis. However, they do not use them often enough to have to commit them to memory. This is a list of MySQL commands I find myself using quite often.

Show available databases:

SHOW DATABASES;

Set MySQL Command Line To Use a Specific Database:

USE {database_name};

See all users and their hosts:

USE mysql;
SELECT user, host FROM user;

Creating a database:

CREATE DATABASE {database_name};

Creating a user:

CREATE USER '{username}'@'{host}' IDENTIFIED BY '{password}';

Grant a user ALL privileges to specific database:

GRANT ALL PRIVILEGES ON {database_name}.* TO '{username}'@'{host}';
FLUSH PRIVILEGES;

Grant a user ALL privileges to ALL databases:

GRANT ALL PRIVILEGES ON *.* TO '{username}'@'{host}';
FLUSH PRIVILEGES;

Author: Joshua Johnson

My name is Joshua Johnson and I am the founder of UA1 Labs. I am passionate about helping other developers to become successful in their paths. When I started developing software, I didn't have many resources to help me out. UA1 Labs is my way of giving back to all those who helped me.

Leave a Reply

Your email address will not be published. Required fields are marked *