MySql Create New Database

Open Terminal and type this to Log into MySql as root:

$ sudo mysql -u root

login

Type it to Create new Database

mysql> CREATE DATABASE BIL_359;

createdb

MySql Create New Table

Firstly select a Database

mysql> USE BIL_359;

usedb

We want to create table with 3 columns as id, name, age.

id is Primary Key and int, name is Varchar, age is int.

mysql> CREATE TABLE bil_359_omeraltuntas(id INT NOT NULL AUTO_INCREMENT, name VARCHAR(50) NOT NULL, age INT NOT NULL, PRIMARY KEY(id));

createtable

Verify that the table is created using the DESCRIBE command:

mysql> DESCRIBE bil_359_omeraltuntas;

describe

Insert Rows to Table

Insert row to table:

mysql> INSERT INTO bil_359_omeraltuntas(name, age) VALUES("omer altuntas", 20);

insert

Verify that the row is inserted using the SELECT command:

mysql> SELECT * FROM bil_359_omer_altuntas;

select

Now Insert many row:

mysql> INSERT INTO bil_359_omer_altuntas(name, age) VALUES ("muhammed basoglu", 20), ("ayse yilmaz", 29), ("sezen aksu", 50);

insertMany

Type it again:

mysql> SELECT * FROM bil_359_omer_altuntas;

select2

Backup Single Table

Logout from MySql

mysql> exit;

exit

Type it to backup single table

$ sudo mysqldump BIL_359 bil_359_omer_altuntas > bil_359_omer_altuntas.sql

backup

Now Create different Database:

$ sudo mysql -u root
mysql> CREATE DATABASE BIL_359_BACKUP;

createnewdb

And logout:

mysql> exit;

Type this to restore table:

$ sudo mysql -u root BIL_359_BACKUP < bil_359_omer_altuntas.sql

restore

Check.

$ sudo mysql -u root
mysql> USE BIL_359_BACKUP;
mysql> SELECT * FROM bil_359_omer_altuntas;

check