- A+
1.msyql基础操作
2.常用的sql技巧
3.sql语句优化
4.mysql数据库优化
5.myisam表锁
6.msyql服务器本身优化
一、mysql的基础操作
a. mysql表复制
create table t2 like t1;
insert into t2 select * from t1;
b. msyql索引
create 不能创建主键索引所以推荐用alter来创建索引
1. alter table 用来创建普通索引
alter table t1 add index index_name (column_list);//创建
alter table t1 add unique un_name(column_list);
alter table t1 add primary key (column_list);
alter table t1 drop index in_name;//删除
alter table t1 modify id int unsigned not null;//删除自增
alter table t1 modify id intunsigned not null auto_increment;//添加自增
alter table t1 drop primary key;//删除主键
2. create 创建索引
create index index_name on table_name(column_list)
show index from t1\G
drop index un_name on t1;
c. msyql视图
create view v_t1 as select * from t1 where id>4 and id<8;//穿件视图
drop view v_t1;//删除视图
d. msyql内置函数
字符串函数
concat(string2 [...])//链接字符串
select concat ("hello ","world") myname
lcase(string2) //转换成小写
select lcase("MYSQL");
ucase(string2)//转换成大写
select ucase ("msyql");
length(string)//string长度
select length("linux");
ltrim(string2)//去除前端空格
select ltrim(" linux");
rtrim(string2)//去除后端空格
select rtrim("linux ");
repeat(string2,count)//重复count次
select repeat("linux,",3);
replace(str,search_str,replace_str)//在str中用replace_str替换search_str
select replace("linux is very good","linux","php");
substring(str,position[,lenght) //从str的position开始,取length个字符
select substr("linux is very good!",1,5);
space(count)//生成count个空格
select space(10);//生成十个空格
select concat(space(10),"linux");
e. mysql预处理语句
f. mysql事务处理
g. mysql存储
h. msyql触发器
i. 重排auto_increment值
- 我的微信
- 这是我的微信扫一扫
-
- 我的微信公众号
- 我的微信公众号扫一扫
-