Useful MySQL Commands

Users

List All Users

mysql> select * from mysql.user;
mysql> select host, user, authentication_string from mysql.user;

References

Create Users

mysql> CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
mysql> GRANT ALL PRIVILEGES ON database . * TO 'newuser'@'localhost';
mysql> FLUSH PRIVILEGES;

References

Databases

List Databases

mysql> show databases;

Change Database

mysql> use db_name;

Show Tables in Database

mysql> show tables;

References

Backup and Restore

Backup

$ mysqldump -p --all-databases > bookstack.sql

References

Restore

$ mysql < bookstack.sql
$ mysql < 'FLUSH PRIVILEGES;'

References

No Comments
Back to top