ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
- 基本语句 ~~~ mysql -u root -p 登录数据库 create database DB 创建数据库db drop database DB; 删除数据库 use DB 选择数据库 show databases; 显示所有数据库 create table if not exists `runoob_tbl`( `runoob_id` int unsigned not null auto_increment comment "描述", `runoob_title` varchar(100) default "0" not null , `submission_date` date, primary key ( `runoob_id` ) )engine=InnoDB default charset=utf8;// Myisam drop table if exists T1,T2;//删除表 show tables 显示所有表 desc T1 显示表结构 show create table T1 显示表结构SQL; alter table T1 rename NEWT1 修改表名 alter table biao modify id int(5) 修改表字段类型 alter table T1 add qqq varchar(10) not null 添加字段 alter table T1 change id id1 char(32) not null 修改字段名 alter table T1 drop id 删除字段 ~~~ -增删改 ~~~ insert into Table(id,name) values (null,'Li') ;插入数据 insert into T(id,name) values (null,'Li'),(null,"Zhao"); insert into T values (null,"Li",null,"数据");插入所有列 insert into T(id,name) select id,name from T2; 查询插入 insert ignore into Table(id,name) values (null,'Li') ; 唯一索引插入 有效防止重复数据 update T set name='Li' where id=1; 更新 update t set num=num+1 where id=1 自动加一 update T left join T1 on T.id=T1.id set u='1',u1='2' where id=1;多表更新 update T set user=replace(user,'a','a1') 替换表字段 update bleA a inner join B b on a.id = b.id set a.name = b.name 查询更新 delete from T where id =1;删除 delete from T where id in(1,2,3);删除多条 truncate table T 清空表 ~~~ - 索引 ~~~ create unique index i on test(openid,rid); unique是唯一索引,默认不是,大于字符串字段需要指定长度 alter table test add unique index ii(rid) 同上 alter table testadd primary key(id); 主索引 alter table test drop index i;删除索引 drop index ion test 删除索引 先改后添加 show index from test; ~~~