Useful MySQL Commands

Below is a list of very common MySQL/MariaDB commands that any developer should know by heart.

Export MySQL Database

mysqldump -u username -p database_name > dump.sql

Import MySQL Database

mysql -u username -p -h servername database-name < data.sql

Login MySQL Database

mysql -uusername -p

Create MySQL Users

CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON database . tablename TO 'username'@'localhost'; 
// Note user can be assigned to all databases 
GRANT ALL PRIVILEGES ON * . * TO 'username'@'localhost';

Change MySQL User Password

ALTER USER 'user-name'@'localhost' IDENTIFIED BY 'NEW_USER_PASSWORD';FLUSH PRIVILEGES;

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.