Upload
bob-huang
View
436
Download
4
Embed Size (px)
Citation preview
1
MySQL展示功能与源码对应丹臣 / 赵林
2010-10-12
提 纲• Mysql 客户端的一些展示命令与源码
• Mysqld 服务端的展示命令与源码
• Mysql 复制状态信息的查看命令与源码
• Innodb monitor 信息展示与源码
客户端 status 命令
客户端 status 命令client/Mysql.cc 源文件
…
客户端 status 命令这部份信息来自于哪里?
Sql_parse.cc 源程序中的 dispatch_command 函数
服务端常用的一些命令• show processlist
• show authors
• show contributors
• show create table / view
• show create database
• show privileges
• 神奇的 information_schema
Show processlist
show processlist三个步骤:1. 先定义 id,user,Host,db,Command,Time,State,Info 字段信息到 field_list 变量中 , 并通过
protocol->send_fields 发送到客户端
2. 锁定线程总数,遍历所有线程,将所有线程的信息填入 thread_infos 链表变量中
3. 向客户端传送 thread_infos 链表中的数据 , 通过 protocol->write() 完成写操作
实际中遇到的问题: 如果一个 mysql 线程很多,那么大部份的 sleep 线程将干扰查看 processlist 列表
Show authors
show contributors
show create table / view
show create database
show privileges
information_schema 中的对象
schema_information 中的对象
st_schema_table 结构体定义
show table statusTable 的各种信息,都在 tables_fields_info[] 数组里定义义 ,Name,Engine,Version,Row_format,Rows,Avg_row_lenght,Data_length 等等
show table status再看 ST_SCHEMA_TABLE schema_tables[] 关于 tables 的定义
表的名字: TABLES表结构的定义: tables_fields_info表的创建函数: create_schema_table填冲数据函数: by function get_all_tables and get_schema_tables_record
MySQL 复制的常用命令• show slave status;
• show master status;
show slave statussql/Slave.cc 源文件
如何把一台mysql 做成多台
master 的slave?
如何把一台mysql 做成多台
master 的slave?
show master statussql/Sql_repl.cc 源文件
Show innodb status
show innodb status
srv_printf_innodb_monitorINNODB MONITOR
OUTPUT
srv_printf_innodb_monitorINNODB MONITOR
OUTPUT
srv_print_master_thread_info(file)注解: BACKGROUND THREADsrv_print_master_thread_info(file)注解: BACKGROUND THREAD
sync_print(file)注解: SEMAPHORES
sync_print(file)注解: SEMAPHORES
lock_print_info_summary() 汇总事务信息lock_print_info_all_transactions() 每个事务的信息
注解: TRANSACTIONS
lock_print_info_summary() 汇总事务信息lock_print_info_all_transactions() 每个事务的信息
注解: TRANSACTIONS
os_aio_print(file);注解: FILE I/O
os_aio_print(file);注解: FILE I/O
ibuf_print(file) // insert bufferha_print_info(file…) //hash table
注解: INSERT BUFFER AND ADAPTIVE HASH INDEX
ibuf_print(file) // insert bufferha_print_info(file…) //hash table
注解: INSERT BUFFER AND ADAPTIVE HASH INDEX
trx_sys_structtrx_purge_struct
log_print(file)注解: LOGlog_print(file)注解: LOG
log_struct
buf_print_io(file)注解: BUFFER POOL AND MEMORY
buf_print_io(file)注解: BUFFER POOL AND MEMORY buf_pool_struct
ROW OPERATIONS( 根据全局变量值计算 )
ROW OPERATIONS( 根据全局变量值计算 )
ibuf_structhash_table_struct
os_aio_array_struct/** The asynchronous i/o array structure */
sync_array_print_infosync_print_wait_info
sync_array_print_infosync_print_wait_info
/** Synchronization array */ sync_array_struct
源文件位置: storage/innodb_plugin/srv/srv0srv.c
Innodb monitor 信息展示与源码
…….
srv/Srv0srv.c 源文件中的 srv_monitor_thread 主函数INNODB TABLESPACE and TABLE MONITOR OUTPUT
dict_table_print_low, dict_update_statistics_low,dict_col_print_low, dtype_print
收集表与索引统计数据
Follow me
• 团队 blog:http://www.taobaodba.com
• 个人 blog:http://zhaolinjnu.blog.sohu.com
• Twitter:http://twitter.com/zhaolinjnu
• 新浪微博: http://t.sina.com.cn/zhaolinjnu
• Email:[email protected]