mysql -h 主机名 -u 用户名 -p
h,u,p三个参数 注意没有;
create database 数据库名;
use 数据库名;
drop database 数据库名;
下面是针对表的操作!
create table 表名称(列声明);
create table students ( id int unsigned not null auto_increment primary key, name char(8) not null, sex char(4) not null, age tinyint unsigned not null, tel char(13) null default "-" );
alter table 表名 rename 新表名;
drop table 表名;
alter table 表名 add 列名 列数据类型 [after 插入位置];
alter table 表名 change 列名称 列新名称 新数据类型;
alter table 表名 drop 列名称;
下面是数据操作
select 列名称 from 表名称 [查询条件];
select * from students;
条件:select 列名称 from 表名称 where 条件;
条件实例:
查询年龄在21岁以上的所有人信息: select * from students where age > 21;
查询名字中带有 "王" 字的所有人信息: select * from students where name like "%王%";
查询id小于5且年龄大于20的所有人信息: select * from students where id<5 and age>20;
insert [into] 表名 [(列名1, 列名2, 列名3, ...)] values (值1, 值2, 值3, ...);
insert into students values(NULL, "王刚", "男", 20, "13811371377");
部分数据
insert into students (name, sex, age) values("孙丽华", "女", 21);
delete from 表名称 where 删除条件;
上面三个总体上来说是对行操作!
而下面这个是二维的
update 表名称 set 列名称=新值 where 更新条件;