Home  • Database • MySQL

Mysql Command

MySQL # How to enter mysql
=> mysql -h localhost -u root -p

Make sure that your server is switched on.

# How to create database
=> create database databse_name;
# How to delete database
=> drop database database_name;
# How to back-up database
//first exit from mysql by q or exit;
	=> mysqldump -u root -p database_name>path_drive:file_name.sql
# How to view database list
=> show databases;	
# How to select specific database from database list
=> use test/database_name;		//here test is a database name
# How to create table in database from .sql file
=> source D:filename.sql
# How to create table in database in hard coding
=> use database_name;
	create table table_name (id int(10) primary key auto_increment,
							field_name varchar(50) not null;
							field_name varchar(50),
							field_name text,
							etc);
# How to view table in database
=> show tables;
# How to view table field in database
=> desc table_name;
# How to insert data in table
=> insert into table_name(field_name1,field_name2....etc) values('field_name1_value','field_name2_value'.....etc);
# How to show data in a table
=> select * from table_name;
	=> select * from table_name where field_name = 'value';
# How to show data between two number of a table
=> select * from table_name where id>value and id<value;
# How to add field in a table
=> alter table table_name add column field_name varchar() after field_name;
# How to delete field/column in a table
=> alter table table_name drop field_name;
# How to change field/column in a table
=> alter table table_name change old_field_name new_field_name with datatype as /varchar()/ /not null if required/;
# How to rename table_name in a database
=> rename table table_name to new_table_name;
# How to update data in a table
=> update table_name set field_name='value', field_name='value' where id=id-no;
	=> update table_name set field_name='value', field_name='value' where field_name='value';
# How to delete a row/record in a table
=> delete from table_name where id='value';
# How to delete table content/data
=> truncate table_name;
	=> delete from table_name;		//to delete table content/data but start after previous record number
# How to delete table
=> drop table table_name;

Entering the DOS mode and Mysql bin folder.

To using the mysql command first go to the DOS mode then run the mysql.To using the DOS mode go to the run command by pressing windowskey+r or from the startmenu then click on the run command. After enabling the run command, write cmd then press ok. A black screen window will appear which is called DOS mode. Entering DOS mode by cmd After enter the DOS mode enter mysql bin folder like this
C:Usersparsonal>cd
C:>
C:>cd xampp
C:xampp>cd mysql
C:xamppmysql>cd bin
C:xamppmysqlin>
Enter mysql through xampp If your server is install in different directory or other drive just change the drive like this
C:Usersparsonal>F:
F:>

Comments 3


50
thx
so useful. jajakallah

Share

About Author
Mir  Samsuzzoha
Copyright © 2024. Powered by Intellect Software Ltd