MYSQL

Login:

mysql -u root -p

List databases:

MYSQL> SHOW DATABASES; 

Delete database:

MYSQL> DROP DATABASE database.name; 

Make new database:

MYSQL> CREATE DATABASE database.name; 

List users:

MYSQL> SELECT user FROM mysql.user;

Make new user:

MYSQL> CREATE USER 'user.name'@localhost IDENTIFIED BY 'password'; 

Delete user:

MYSQL> DROP USER user.name@localhost; 

Gives all rights to user over a certain database (replace database.name with * for all databases):

MYSQL> GRANT ALL PRIVILEGES ON database.name .* TO 'user.name'@localhost IDENTIFIED BY 'password';

Refreshes privileges, a must after a change:

MYSQL> FLUSH PRIVILEGES; 

Lists user rights:

MYSQL> SHOW GRANTS FOR 'user.name'@localhost; 

Exports (dumps) the database:

mysqldump -u user.name -p database.name > export.file.name.sql 

Shows original (exported) database name:

head -n 5 export.file.name.sql 

Imports dump of some database to your database:

mysql -u user.name -p database.name < export.file.name.sql 

Leave a Comment

Tested on Ubuntu & Pop OS