过程/函数:
//显示数据库中所有存储的存储过程基本信息,包括所属数据库,存储过程 show procedure/function status [like 'pattern'] //从系统表中查询某一存储过程的相关信息 select * from mysql.proc where name = 'procedure_name' //创建过程 create procedure count_user() select count(*) as user_number from mysql.user; //调用过程 call count_user(); //删除过程 drop procedure procedure_name //指定的存储过程的创建信息 show create procedure procedure_name
视图:视图作为一张表的查询封装,可以很好的起到中间组件的作用,其实视图也是一张表,虚拟表
//创建视图 create view user_view as select host, user from mysql.user; //使用视图 select * from user_view [where condition.....] //删除视图 drop view user_view //查看视图 //show table status 会罗列出当前数据库所有的表的状态,视图作为一张特殊表也会被列出来且comment="view" show table status where comment='view' //查看视图创建信息 show create view view_name
查看存储过程/函数/触发器/事件/视图
show procedure status show function status show triggers show events show table status [from dbname] [like 'pattern'] where comment="view"
查看表状态:查看当前数据库或指定数据库的所有表的状态信息
show table status [from dbname] [like 'pattern']
查看数据库使用量
//每个数据库的信息图表 use information_schema; //查看所有数据库的总大小 select concat(round(sum(data_length/1024/1024),2),'MB') as data_size from tables; //查看某一数据库的大小table_schema select concat(round(sum(data_length/1024/1024),2),'MB') as data_size from tables where table_schema='dbname'; //查看某一表的大小 select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables where table_schema='dbname' and table_name='table_name';
导出数据到文件 into outfile 'file_path_name'
select * FROM test.table into outfile '/tmp/data.txt' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n';
导入数据到数据库 load infile 'file_path_name'
LOAD DATA INFILE '/tmp/data.txt' INTO TABLE test.table_same_create_info FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n'
FIELDS TERMINATED BY ',' 字段间分割符
OPTIONALLY ENCLOSED BY '"' 将字段包围 对数值型无效
LINES TERMINATED BY '\n' 换行符