show databases; 显示所有已经存在的数据库
create database test; 创建名字为test的数据库
drop database test; 删除名字为test的数据库
use test;使用名字为test的数据库
show tables; 显示这个数据库中的所有数据表
create table player(id int not null auto_increment primary key,name varchar(16) not null,level int not null default “0”,fightingValue int not null default “5”);创建一个名字为player的表,表里一共三列属性id,name,level,fightingValue;
describe player; 显示player这张表的属性
select * from player 遍历这张表的所有数据
insert into player (id,name,level,fightingValue)values (1,”法师”,1,10);增加一行数据
select name from player where id = 2; (查询player这张表中id 为 2 这一行的名字信息)
select * from player order by level asc;对player这张表按等级排序(正序)
select * from player order by fightingValue desc;对player这张表按战斗力排序(倒序)
delete from player where id = 1;删除player这张表中的id = 1的一行数据
update player set fightingValue = 50 where id = 1;更新player这张表中id为1的玩家的战斗力为50;
alter table player add column vipLevel int not null default “0”;增加player表中的一个vipLevel字段,类型为int;
alter table player drop vipLevel;删除player表中的vipLevel字段
alter table player rename as player1;将player这张表的名字改为player1;
mySql支持的常用数据类型:
tinyint,int,varchar,char,float,double