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

查看从库进程

 

转载于:https://www.cnblogs.com/uptothesky/p/8890670.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值