Select | Show
| Drop | Alter |
Create | Delete | Concat |
SELECT
Select user();
Select version(); //version of mysql
Select current_date()
Select now(); //current date&time
Select database(); //show current db
Select password ('username') //show long hashed password
SHOW
Show grants for dbuser@localhost;
Show database;
Show tables;
Show Create Database db_name;
Show Create Table tb_name;
DROP
use db_name;
Drop Database db_bame
Drop Table tb_name
Drop User u_name
Back
ALTER
Alter Table tb_name add column col_name datatype after whatcolumn
Alter Table tb_name drop column col_name
Alter Table tb_name modify col_name VARCHAR (30)
Alter Table tb_name change old_col_name] new_col_name varchar (50);
DEL/UPD/Trunc/Desc
Delete from table where col=" " ;
Update tb_name set col1='A' , col2='B' where user=" allen";
Truncate table tb_name
Desc table ; // display info of each table columns
CREATE
Create Database db_name;
LOAD DATA LOCAL INFILE
'/path/pet.txt' INTO TABLE
pet;
Back
CONCATENATION (append col to
end of col)
col3=CONCAT(
col1, col2) // concatenate col2 to the end of col1 =>col3
eg
$id=$_POST['num']; // form method
$updsoln = "UPDATE
cec SET Solution=concat(Solution, Addsoln) WHERE Num=$id";
mysql_select_db($database_conn_cec,
$conn_cec);
$Result2 = mysql_query($updsoln,
$conn_cec) or die(mysql_error());
Back
|