As we all know, the hallmark of a good technician is the balance between laziness and productivity, where the important thing to note is that we are usually only productive about something that we want to be lazy about. I don't know if that makes much sense but I do know I have to keep looking up these simple commands online on how to do simple MySQL tasks on the command line, so I made a collection of commands I often use and put them on here in quick and easy to copy-and-paste format. So enjoy, if you enjoy this sort of technical mumbo-jumbo that drives most of my customers nuts.


Log in to MySQL command line as root user

mysql -u root -p


Add a new database

create database namegoeshere;


Give a user access to a database (creates user if non-existent)

grant all privileges on namegoeshere.* to user@localhost identified by 'password';


Drop a database

drop database namegoeshere;


Export/dump database to sql text file

mysqldump -u username -p namegoeshere > filename.sql


To import database from dump file

mysql -u username -p  namegoeshere < filename.sql

Comments are closed.