MySQL Basic Commands
1. how many databses are exists in mysql
show databases;
2. how to open existing database
use db_name;
3. how to create database;
create database db_name;
4. if database already exists , then how to create new with same name;
drop database if exists db_name;
5. how to view the list of tables exists
show tables;
6. how to view the structure of existing table;
desc table;
7. how to create table;
create table tb_name
(
adm_no varchar(8) primary key,
name varchar(25),
age int,
gender varchar(6) default 'male',
address varchar(100)
);
8. how to insert data into table
a) insert into tb_name values('mrt-1001','lokesh',31,'male','chandigarh');
b) insert into tb_name(adm_no,age,name) values('mrt-1002',25,'manu');
9. how to fetch the data from table
select * from tb_name;
// it will display all fields value of all rows
select name,age from tb_name;
//it will display selected fields value of all rows
select * from tb_name where name='lokesh';
// it will display all fields value of conditional row
select name,age from tb_name where age<=30;
// it will display selected fields value of conditional row
select * from tb_name order by name; // alphabetically ascending order
select * from tb_name order by name desc; // alphabetically descending order
10. how to modify the data of a table
update tb_name set address='punjab' where adm_no='mrt-1002';
11. how to delete data from table
delete from tb_name where adm_no='mrt-1002';
12. how to delete table from database
drop table if exists tb_name;