A Quick MySQL How-To

 

  1. Connect to mysql server

 

mysql –u user_id –p

 

or

 

mysql –u user_id –p database_name

 

  1. Show available databases

 

mysql> show databases;

 

  1. Choose a database

 

mysql> use database_name;

 

  1. Show table names of the current database

 

mysql> show tables;

 

  1. Show schema definition of a table

 

mysql> describe table_name;

 

  1. Execute a SQL statement online

 

mysql> sql_statement;

 

  1. Show all rows of a table

 

mysql> select * from table_name;

 

  1. Delete a table

 

mysql> drop table table_name;

 

  1. Execute a SQL script file

 

mysql> source sql_script_file_name

 

  1. Load a data file to a table. Note columns in the data file must be separated by <tab>

 

mysql> load data local infile “absolute_path_to_the_data_file” into table table_name;

 

  1. Exit from mysql

 

mysql> quit