I use MySQL a lot at work and usually have a MySQL client console open. This page is a collection of often used SQL commands that I use to create a new user or dataabse before starting a new Rails or Python/Flask project.
Create new database and user
To create new database banks_production, run this:
CREATE DATABASE banks_production
To create new user teller with password teller123
CREATE USER 'teller'@'localhost' IDENTIFIED BY 'teller123';
Privileges
To grant all privileges on database banks_productionto user teller, run this:
GRANT ALL PRIVILEGES ON banks_production.* TO 'teller'@'localhost';
FLUSH PRIVILEGES;
Change MySQL password
To change the root user's password to NewPass, run this:
MySQL 5.7.6 and later:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPass';
MySQL 5.7.5 and earlier:
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('NewPass');
Delete user
To delete user teller, run this:
DROP USER 'teller'@'localhost';
Related Posts
If you have any questions, please contact me at arulbOsutkNiqlzziyties@gNqmaizl.bkcom. You can also post questions in our Facebook group. Thank you.