track ip addresses, phone numbers, etc

Various MySQL commands

Published on 01 August 2016

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';


To grant all privileges on database banks_productionto user teller, run this:

GRANT ALL PRIVILEGES ON banks_production.* TO 'teller'@'localhost';

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';

Created on 01 August 2016

Affiliate Disclosure: Some of the links to products on this blog are affiliate links. It simply means, at no additional cost to you, we’ll earn a commission if you click through and buy any product.