一、mysql編碼設(shè)定
1、查看mysql服務(wù)的編碼
show?variables?like?'char%';
2、修改數(shù)據(jù)表的編碼
alter?table?test?character?set?utf8;
3、修改數(shù)據(jù)表的某個(gè)字段名的編碼
alter?table?test?change?code?code?varchar(32)?character?set?utf8?not?null;
二、會話變量和全局變量
1、會話變量
show?session?variables;
2、會話變量的模糊查詢
show?session?variables?like?'auto%';
3、設(shè)置回話
set?@@session.autocommit?='off';
4、查看全局變量
show?global?variables;
三、存儲過程
1)、存儲過程增強(qiáng)了SQL語言的功能和靈活性
2)、存儲過程允許標(biāo)準(zhǔn)組件是編程
3)、存儲過程能實(shí)現(xiàn)較快的執(zhí)行速度
4)、存儲過程能夠減少網(wǎng)絡(luò)流量
5)、存儲過程可被作為一種安全機(jī)制來充分利用
1、使用:
1)、首先選中數(shù)據(jù)庫
2)、改變分隔符:不要讓;作為執(zhí)行結(jié)束的標(biāo)記。
如:
delimiter?$$;
create?procedure?p_hello()?? begin?? select?'hello';?? select?'world';?? end?? $$;
3)、分隔符改變回來
delimiter?;
4)、調(diào)用上面的存儲過程
call?p_hello;
2、定義存儲過程局部變量
1)、第一種變量賦值
create?procedure?p_vartest()?? begin?? declare?a?varchar(20)?default?'abc';?? select?a;?? end?? $$;
2)、第二種變量賦值
create?procedure?p_vartest2()?? begin?? declare?inta?int;?? set?inta?=?10;?? select?inta;?? end?? $$;
3)、存儲過程的傳參
create?procedure?p_vartest3(in?p_int?int)?? begin?? select?p_int;?? set?p_int?=?p_int?+?1;?? select?p_int;?? end?? $$;
a、定義一個(gè)變量
set?@p_int?=?3;
b、調(diào)用存儲過程
call p_vartest3(@p_int);
d、查看數(shù)據(jù)庫中的變量的變化
數(shù)據(jù)庫里的變量并沒有被修改,表示存儲過程傳值只是把變量進(jìn)行賦值。
?以上就是MySQL高級一的內(nèi)容,更多相關(guān)內(nèi)容請關(guān)注PHP中文網(wǎng)(www.php.cn)!
? 版權(quán)聲明
文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載。
THE END