Basics

Create Database

CREATE DATABASE tutorial;

Access Database

# Login to database (-u username, -p authenticate with password)
mysql -u root -p 
# Enter Password: **********

# You can also login
sudo mysql

Backup Database

# Login to database
sudo mysql

# Create a new database
mysql > CREATE DATABASE tutorial_backup;

# Exit mysql with exit command and export table tutorial into a file
mysqldump -u root -p tutorial > tutorial.sql
# Enter Password: **********

# Import the tutorial table into a backup table, for example tutorial_backup
mysql -u root -p tutorial_backup < tutorial.sql
# Enter Password: **********

Create Table

Insert Data Into Table

Deleting Data

Updating Data

Add Extra Column

Example Query

Aggregate Function

  • COUNT(*), COUNT(column)

  • MIN(column)

  • MAX(COLUMNS)

  • AVG(column)

  • SUM(column)

SQL Joins

INNER JOIN

Produces the set of records that match in both table1 and table2 (matching part of both tables).

FULL OUTER JOIN

Produces the set of records in table1 and table2, that matches records from both tables (all records from both tables, null value if there is no record in one of them).

LEFT OUTER JOIN

Produces a set of records from table1 + matching records in table2 (full table 1 + common part with table 2, null values if there is no record in table 2).

If you want just records from table1 without the matching part with table2 (without null values) you can use the following query:

On the other hand, if you need both tables records but no matching part you can use:

Last updated

Was this helpful?