创建数据库
create database <数据库名>;
删除数据库
drop database <数据库名>;
选择数据库
mysql -u root -p Enter password :******* mysql> use test Database changed
创建数据表
create table table_name (column_name,column_type)
栗子:
create table if not exists `test`( `id` int unsigned auto_increment, `title` varchar(10) not null, primary key (`id`) );
删除数据表
drop table table_name;
mysql> use test Database changed mysql> drop table test; Query OK, 0 rows affected (0.05 sec)
插入数据
insert into table_name (field1,field2,...fieldN) values (value1,value2,...valueN);
栗子:
mysql> insert into goods -> (id,price) -> values -> (1,10); Query OK, 1 row affected (0.00 sec)
查询数据
select column_name,column_name from table_name [where Clause] [limit n ][ offset m]
你可以使用星号(*)来代替其他字段,SELECT语句会返回表的所有字段数据
你可以使用 WHERE 语句来包含任何条件。
你可以使用 LIMIT 属性来设定返回的记录数。
你可以通过OFFSET指定SELECT语句开始查询的数据偏移量。默认情况下偏移量为0。
栗子:
select * from goods
update更新
update table_name set field1=new_value1,field2=new_value2 [where clause]
栗子:
mysql> update goods -> set price=100 -> where id=1;
delete 语句
delete from table_name [where clause]
栗子:
delete from goods where price = 100;
like子句
select field1,field2,...fieldN from table_name where field1 like condition1 [and [or]] field2 = 'somevalue';
union操作符
SELECT expression1, expression2, ... expression_n from tables [where conditions] union[all | distinct] select expression1, expression2, ... expression_n from tables [where conditions];
排序
select field1,field2,...fieldN from table_name1,table_name2,...table_nameN order by field1