查看所有可用字符集:
show character set;
desc information_schema.character_sets
查看系统的校对规则:
show collation like ‘****‘
desc information_schema.collations;
服务器字符集,校对规则(没有指定字符集则使用默认字符集,没有指定校对规则则使用字符集默认的校对规则)
查询服务器字符集:show variables like ‘character_set_server‘;
查询服务器校对规则:show variables like ‘collation_server‘;
数据库字符集,校对规则
查询数据库字符集:show variables like ‘character_set_database‘;
查询数据库校对规则:show variables like ‘collation_database‘;
表字符集,校对规则
show create table tablename \G;
/**********************索引*******************************/
创建索引:create [unique|fulltext|spatial]index index_name
[using index_type]
on table_name(index_col_name)
index_col_name:
col_name[(length)][ASC|DESC]
删除索引:drop index index_name on table_name;
修改示图:
alter [algorithm={undefined|merge|temptable}]
view view_name[(column_list)]
as select_statement
[with[cascaded|local]check option]
删除视图:
drop view[if exit] view_name[,view_name]...[restrict|caseade]
查看视图:
show tables;
show table status like ‘****‘;
show create view view_name;
desc information_schema.views;
create function sp_name([func_parameter][....])
returns type
[characteristic...]routine_body
proc_parameter:
[in|out|inout]param_name type
func_parameter:
para_name type
type:
any valid mysql data type
修改:
alter {procedure|function} sp_name [characteristic...]
调用:
call sp_name([parameter][....])
删除:
drop {procedure|function}[if exit] sp_name
查看:
show {procedure|function} status [like ‘***‘]
show create {procedure|function} sp_name
/******************变量的使用***********************/
定义:
declare var_name[,...] type [default value];
赋值:
set var_name=exp[,var_name=epx]...
select col_name[,...] into var_name[,...]table_expr //查询赋值
/********************定义条件和处理**********************/
定义条件:
declare condition_name condition for condition_value;
condition_value:
sqlstate[value]sqlstate_value|mysql_error_code
定义条件处理:
declare handler_type handler for condition_value[,...] sp_statement;
hadler_type:
continue|EXIT|UNDO
condition_value:
/*****************光标的使用*************************/
申明光标:
declare cursor_name cursor for select_name
打开光标:
open cuesor_name
操作光标:
fetch cuesor_name into var_value [,var_name]...
关闭光标:
close cursor_name
/******************流程控制***********************/
if search_condition then statement_list
[elseif search_condition then statement_list]...
[else statement_list]
endif
/*****************/
case case_value
when when_value then statement_list
[when search_condition then statement_list]
[else statement_list]
end case
/*****************/
case
when search_condition then statement_list
[when search_condition then statement_list]
[else sattement_list]
end case
/*****************/
[begin_label:]loop
statement_list
end loop[end_label]
/*****************/
退出循环leave/iterate
/*****************/
[begin_label:]repeat
statement_list
until search_condition
end repeat[end_label]
/*****************/
[begin_label:]while search_condition do
statement_list
end while[end_label]
/******************事件调度器*****************/
说明:按自定义的时间周期触发某种操作
create event event_name
on schedule at current_timestamp+interval 1 hour
do
/**************触发器**********************/
创建:
create trigger trigger_name trigger_event
on table_name for each trigger_stmt
删除:
drop trigger[schema_name]trigger_name
查看:
show triggers \G;