1. To login (from unix shell) use -h only if needed.
# /usr/bin/mysql -h hostname -u root -p password -P port_number
2. Create a database on the sql server.
mysql> create database [databasename];
3. List all databases on the sql server.
mysql> show databases;
4. Switch to a database.
mysql> use [db name];
5. To see all the tables in the db.
mysql> show tables;
6. To see database’s field formats.
mysql> describe [table name];
7. To delete a db.
mysql> drop database [database name];
8. To delete a table.
mysql> drop table [table name];
9. Show all data in a table.
mysql> SELECT * FROM [table name];
10. Returns the columns and column information pertaining to the designated table.
mysql> show columns from [table name];
11. Show certain selected rows with the value “apple”.
mysql> SELECT * FROM [table name] WHERE [field name] = "apple";
12. Show all records containing the name “Paul” AND the phone number ’888999′.
mysql> SELECT * FROM [table name] WHERE name = "Paul" AND phone_number = '888999';
13. Show all records not containing the name “Merry” AND the phone number ’732788′
order by the phone_number field.[/sql]
mysql> SELECT * FROM [table name] WHERE name != "Merry" AND
phone_number = '732788' order by phone_number;
13. To list all of the table in a particular database
mysql> SHOW FULL TABLES IN rs_hugodb_beta7 WHERE TABLE_TYPE LIKE 'BASE TABLE';
or
mysql> SELECT TABLE_NAME FROM information_schema.tables WHERE TABLE_TYPE LIKE 'BASE TABLE' AND TABLE_SCHEMA LIKE 'database_name';
where database_name is your database name
14. To list all of the view in a particular database
mysql> SHOW FULL TABLES IN database_name WHERE TABLE_TYPE LIKE 'VIEW';
or
mysql> SELECT TABLE_NAME FROM information_schema.tables WHERE TABLE_TYPE LIKE 'VIEW' AND TABLE_SCHEMA LIKE 'database_name';
where database_name is your database name
Reference: