Log into MySQL:
mysql -uUSERNAME -p'PASSWORD'
List Users:
SELECT User FROM mysql.user;
Create & Modify Users:
CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password'; GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';
Once you have finalized the permissions that you want to set up for your new users, always be sure to reload all the privileges with this FLUSH PRIVILEGES;
GRANT [type of permission] ON [database name].[table name] TO ‘[username]’@'localhost’ REVOKE [type of permission] ON [database name].[table name] FROM ‘[username]’@‘localhost’;
ALL PRIVILEGES -- this allows the user all access to a database (or, if no database is selected, across the system) CREATE -- allows them to create new tables or databases DROP -- allows them to them to delete tables or databases DELETE -- allows them to delete rows from tables INSERT -- allows them to insert rows into tables SELECT -- allows them to use the Select command to read through databases UPDATE -- allow them to update table rows GRANT OPTION -- allows them to grant or remove other users' privileges
Delete User:
DROP USER ‘demo’@‘localhost’;
Create Database:
create database <dbname>;
Show Processlist:
mysqladmin processlist
Backup a Single Database:
mysqldump database_name > database_name.sql mysqldump -u'user' -p'passwd' database_name | gzip -c > database_name.sql.gz (or mysqldump -u'user' -p'passwd' database_name | gzip -c > database_name.sql.zip)
Backup Multiple Databases:
mysqldump --databases database_one database_two > two_databases.sql
Backup All Databases:
mysqldump --all-databases > all_databases.sql
Restore a Database:
mysql database_name < database_name.sql
Restore a Single Database from All Databases Backup File:
mysql --one-database database_name < all_databases.sql