Common MySQL Commands With Examples

Everything you need to know

Working with Databases

1. Create a database   CREATE DATABASE db_name;    2. Replace the current database with another one   mysql> USE db_name;

Working with  Tables

1. Creates a new table   CREATE TABLE table_name(Column_name1 datatype, Column_name2 datatype……);   2. Remove a column from table    ALTER TABLE table_name DROP column_name;

1. Create an Index on Table    CREATE INDEX index_name ON table_name (column,…);   2. Create a unique index   CREATE UNIQUE INDEX index_name ON table_name (column,…);

Working with Indexes

1. Create a new view   CREATE VIEW view_name AS Select query;   2. Rename a view   RENAME TABLE view_name TO new_view_name;

Working with  Views

1. Create a stored procedure DELIMITER $$  CREATE PROCEDURE procedure_name(parameter_list) BEGIN  body  END $$  DELIMITER;  

Working with Stored Procedures

1. Display some columns of a table SELECT column1, column2, … FROM Table_name;   2. Group rows   SELECT select_list FROM table_name GROUP BY column_1, column_2, …;

Querying Data from Tables

1. Update all rows in a table   UPDATE table_name SET column1 = value1, …;   2. Delete rows based on a condition   DELETE FROM table_name WHERE condition;

Modifying Data in Tables

1. Connect MySQL server with username and password   mysql -u [username] -p;   2. Exit MySQL command line  mysql> system clear;

MySQL command-line client commands

Find out more about MYSQL commands along with their syntax.

Click Here