ARTICLES

MYSQL COMMANDS

For those of you, like myself, who don't use Mysql too often, it is worth having a reference for MySQL commands.

These are just a very simple selection of basic commands that you will need to get a database and users setup quickly.

 

Show all users:

mysql> select * from mysql.user;

 

Create Database:

CREATE DATABASE mydb CHARACTER SET utf8 COLLATE utf8_bin;

 

Create User:

CREATE USER 'myuser'@'%' IDENTIFIED BY PASSWORD 'password';

 

Grant all access to database for user:

GRANT ALL ON mydb.* TO 'myuser'@'%';

GRANT ALL ON mydb TO 'myuser'@'%';

GRANT CREATE ON mydb TO 'myuser'@'%';

 

Use this at the end of running any commands to save permanently:

FLUSH PRIVILEGES;

 

References and further reading:

http://stackoverflow.com/questions/15278018/granting-privileges-to-a-new-user-in-mysql?noredirect=1&lq=1

http://alvinalexander.com/blog/post/mysql/show-users-i-ve-created-in-mysql-database

http://stackoverflow.com/questions/5016505/mysql-grant-all-privileges-on-database