Below are some basic MySQL commands often used when setting up websites or web applications.
Access the MySQL CLI
mysql -u [username] -p [databasename]
Create a database
CREATE DATABASE [databasename];
List all databases
SHOW DATABASES;
Switch to a database
USE [databasename];
List tables
SHOW TABLES;
Show all columns in a table
show columns from yourTableName;
Create a new MySQL user
CREATE USER [username]@'localhost' IDENTIFIED BY 'password';
// password needs to be in quotes
List all users
SELECT host, user FROM mysql.user;
Add a new user to a database, for all tables (*)
GRANT ALL PRIVILEGES ON [databasename].* TO [username]@'localhost';
Flush user privileges
FLUSH PRIVILEGES;
Dump a database’s contents to a file
mysqldump -u [username] -p [database-you-want-to-dump] > [path-to-place-data-dump]