Basic Commands of Mysql Database

In this post, I have written some basic mysql commands which we are using regularly during  development. we can use the given below commands into windows’s cmd, linux terminal or shell.

1- Login into database:

$ mysql -h hostname -u username -p

After entering the  MySQL user’s  password into the prompt,you will be able to start building your MySQL database.Use -h only if needed, it’s not need to connect same server database(localhost).

2- Show list of all databases into db:

show databases;

3- Create New Database:

create database [database_name];

4- Switch to a database:

use [database_name];

5- See all tables in selected database:

show tables;

6- See table’s field format:

describe [table_name];

7- Fetch Data from table or Get Data From table:

select * from [table_name];

8- Get Specific Rows or Specific fields from table:

select [field_name1], [field_name2] from [table_name] where [field_name]='value';

select [field names into comma seperated] from [table_name] where [condtions];

8- Update data into table:

update [table_name] SET [field_name1]='value', [field_name2]= 'value',... where

9- Delete data from table:

delete from [table_name] where [condition];

10- Delete a database:

drop database [database_name];

11- Delete a table:

drop table [table_name];

12- Export a database:

$ mysqldump -u username -p database_name > dump.sql

13- Export big database using gzip:

$ mysqldump -u username -p database_name | gzip > dump.sql.gz

14- Import sql data file into database:

$ mysql -u username -p database_name < data.sql




Leave a Reply

Your email address will not be published. Required fields are marked *