MySQL basics

Install MySQL in Ubuntu

sudo apt-get install mysql-server

Setup root password

mysqladmin -u root password password

​Create a database

1. Login to the mysql console

$ mysql -u root -p

2. Execute the next command

mysql> CREATE DATABASE newdb CHARACTER SET utf8 COLLATE utf8_unicode_ci;

Describe a table

mysql> DESCRIBE <table_name>

This will show the table fields and their features

Delete a database

mysql> DROP DATABASE <database_name>

Erase all the registries in a table

mysql> TRUNCATE TABLE <table_name>

Drop all the tables of a database

mysql -Nse 'show tables' DATABASE_NAME | while read table; do mysql -e "drop table $table" DATABASE_NAME; done