mysql
查询表信息
-- 查询自动提交 show VARIABLES like 'autocommit'; -- 修改自动提交 set autocommit=1; -- 查看表信息 show table status like 'student';
性能剖析
-- 性能剖析开启状态 show VARIABLES like 'profiling'; -- 性能剖析 show profiles;
比如先执行一条语句select * from user;
再执行show profiles; 可以看到结果中有语句的执行时间
接下来执行
show profile for query 35;
可以看到具体的执行步骤占用时间
不过这里是按照顺序排序的,要想按耗时排序,可以使用以下语句
select state,sum(duration) as Total_R, round(100*sum(duration)/ (select sum(duration) from information_schema.PROFILING where query_id=35),2)as Pct_R, count(*) as Calls, sum(duration)/count(*) as "R/Call" from information_schema.PROFILING where query_id=35 GROUP BY state ORDER BY Total_R DESC;
show CREATE table + 表名
查询索引
show index from 表名;
查询状态
show full processlist;
Command列Query表示线程正在执行查询或者正在将结果发送给客户端。
使用show status
show status WHERE variable_name like 'HANDLER%' or variable_name like 'created%';
使用show PROCESSLIST
mysql复制
主库:10.15.4.155
从库:10.15.4.156
在主库和从库创建账号并赋予复制权限
grant replication slave,replication client on *.* to repl@'10.15.4.%' identified by 'xxx'
先查看配置
which mysqld
结果是/usr/sbin/mysqld
再运行
/usr/sbin/mysqld --verbose --help | grep -A 1 'Default options'
结果是
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/etc/my.cnf ~/.my.cnf
编辑主库的/etc/my.cnf,加入以下配置
log_bin=mysql-bin server_id=10
重启MySQL,查看主库状态
show master status;
编辑从库的配置
log_bin=mysql-bin server_id=2 relay_log=/var/lib/mysql/mysql-relay-bin log_slave_updates=1
连接主库
change master to master_host='10.15.4.155', master_user='repl', master_password='xxxx', master_log_file='mysql-bin.000001', master_log_pos=0;
查看从库状态
show slave status;
启动复制
start slave;
再次查看状态
查看主库进程
show processlist\G
查看从库进程