Mysql Command Handbook

Mysql handbook

Here’s a MySql database handbook that I think you will find useful. It consists of common MySql commands that you can enter in on the Mysql client program.

Common MySql Commands

  • Login

    mysql -h hostname -u username -p
  • Create a database

    mysql> create database databasename;
  • Delete database

    mysql> drop database databasename;
  • List all databases

    mysql> show databases;
  • Use a database

    mysql> use databasename;
  • Show all tables

    mysql> show tables;
  • Show table fields

    mysql> describe tablename;
  • Remove table

    mysql> drop table tablename;
  • Show all data in a table

    mysql> select * from tablename;
  • Show column information in a table

    mysql> show columns from tablename;
  • Load a CSV file into a table

    mysql> load data infile '/nameoffile.csv' into table tablename fields terminated by ',' lines terminated by '\n' col1, col2, ... coln);
  • Create a table

    mysql> create table tablename (col1 datatype, col2 datatype,..colN datatype)
  • Delete a row from a table

    mysql> delete from tablename where column='something';
  • Delete a column

    mysql> alter table tablename drop column columname;
  • Add a new column

    mysql> alter table tablename add column columname vartype;

Of Interest