Monday, 29 July 2013

Basic MySQL Commands for Begineers

1. How to login mysql from GNU/Linux shell ???

           $mysql -h username -u root -p

2. How to create a database ???

              mysql> create database [Database_Name];
3. How to list all databases ???

              mysql> show databases;
4. How to list all the tables in a database ???

             mysql> show tables;
5. How to switch to a database ???

            mysql> use [Database_Name];ex[test]
6. How to list database field formats in a table ???

           mysql> describe [Table_Name];ex[dummy]
7. How to delete a database ???

           mysql> drop database [Database_Name];ex[dummy]
8. How to delete a table ???

           mysql> drop table [Table_Name];ex[test]
9. How to list all data in a table ???

          mysql> SELECT * FROM [Table_Name];[test_dummy]
10. How to list certain selected rows with the value “yes”.???

         SELECT * FROM [Table_Name] WHERE [Field_Name] = “yes”;
11. How to list all records containing the name “test” AND the phone number ’1234567890′.???

        SELECT * FROM [Table_name] WHERE [Field_Name] = “test” AND [Field_Name] = ’1234567890′;
12. How to list all records not containing the name “test” AND the phone number ’1234567890′ order by the Field_Name phone_number ???

       SELECT * FROM [Table_Name] WHERE name != “test” AND phone_number = ’1234567890′ order by phone_number;
13. How to list all records starting with the letters ‘verman’ AND the phone number ’26235208′ ???

     SELECT * FROM [Table_Name] WHERE name like “test%” AND phone_number =      ’1234567890′;