有管理员权限的用户,如下图所示: 没有管理权限的用户,如下图所示:: 如果不加full关键字,每条语句的info信息栏只能显示前100个字符。 如果看到“too many connections”的错误信息,想要看看什么线程正在运行,使用show processlist语句是很有用的。mysql数据库会额外保持一个连接,供具有connection_admin或者super权限用户的使用,用以确保管理员能随时连接进来检查系统状况(假设你没有将此权限授予所有用户)。 show processlist输出列详解:
UPDATE trade_order SET state = 'CANCELLED' where state='CANCEL'; error:Multi-statement TRANSACTION required more THAN 'max_binlog_cache_size' bytes of STORAGE; increase this mysqld variable AND try again
2、查看binlog_cache_size,最大值为1G:
1 2 3 4 5 6 7 8
mysql> show variables like '%binlog_cache_size%'; +-----------------------+------------+ | Variable_name | Value | +-----------------------+------------+ | binlog_cache_size | 4194304 | | max_binlog_cache_size | 1073741824 | +-----------------------+------------+ 2 rows in set (0.00 sec)
3、尝试去调高max_binlog_cache_size,在此执行update语句:
1 2 3 4 5 6 7 8 9 10
mysql> set global max_binlog_cache_size=4073741824; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> show variables like '%binlog_cache_size%'; +-----------------------+------------+ | Variable_name | Value | +-----------------------+------------+ | binlog_cache_size | 4194304 | | max_binlog_cache_size | 4073738240 | +-----------------------+------------+ 2 rows in set (0.00 sec)
mysql> UPDATE trade_order SET state = 'CANCELLED' where state='CANCEL' and id >=1 and id <= 1000000; Query OK, 974190 rows affected (2 min 3.48 sec) Rows matched: 974190 Changed: 974190 Warnings: 0 ... ... mysql> UPDATE trade_order SET state = 'CANCELLED' where state='CANCEL' and id >=16000000 and id <= 17000000; Query OK, 982238 rows affected (2 min 37.44 sec) Rows matched: 982238 Changed: 982238 Warnings: 0
每100万更新耗时为2min 40s左右
5、上述方法适用于当前表有主键id且递增的情况。如果该id值从其他关联表获取,可考虑一下方法:
1
mysql> UPDATE trade_order SET state = 'CANCELLED' where state='CANCEL' and id in (select id from (select id from trade_order ORDER BY id ASC LIMIT 1,1000000) as tmp);
该方法涉及到一个子查询,总体执行速度会下降,根据取值范围和当前实际更新的行数,耗时在4min左右:
1 2 3
UPDATE trade_order SET state = 'CANCELLED' where state='CANCEL' and id in (select id from (select id from trade_order ORDER BY id ASC LIMIT 1,1000000) as tmp); Query OK, 981631 rows affected (3 min 49.27 sec) Rows matched: 981631 Changed: 981631 Warnings: 0
/etc/init.d/mysql restart ERROR! MySQL server PID file could not be found! Starting MySQL....................................................................................^C 启动失败,按ctrl+c退出。
3、查看log日志,一直在刷错误日志
1 2
[ERROR] InnoDB: Unable to lock ./ibdata1 error: 11 [Note] InnoDB: Check that you do not already have
4、查看磁盘使用情况
1 2 3 4
df -h Filesystem Size Used Avail Use% Mounted on /dev/sdc1 1.1T 59G 967G 6% /data 数据目录还有很多空间。
当从另一个有不同字符集的列分配列值: UPDATE t1 SET utf8_bin_column=latin1_column; INSERT INTO t1 (latin1_column) SELECT utf8_bin_column FROM t2; 当使用字符串文字为insert或update分配值时: SET NAMES latin1; INSERT INTO t1 (utf8_bin_column) VALUES ('string-in-latin1'); 当从服务端给客户端返回结果: SET NAMES latin1; SELECT utf8_bin_column FROM t2;
mysql> SET NAMES binary; mysql> SELECT LOWER('aA'), LOWER(CONVERT('aA' USING latin1)); +-------------+-----------------------------------+ | LOWER('aA') | LOWER(CONVERT('aA' USING latin1)) | +-------------+-----------------------------------+ | aA | aa | +-------------+-----------------------------------+
insert into music values('BITE'),('There for you'),('Scarborough Fair'),('Shape of You'),('Marvin Gaye'),('Pretty Girl'),('Pretty Boy'),('Walk Away'),('YOUTH'),('Paris');
insert into music values ('Scarborough Fair'),('Shape of You'),('Marvin Gaye'),('Pretty Girl'),('Pretty Boy'),('Walk Away'),('YOUTH'),('Paris');
select count(distinct left(name,1))/count(*) as sel1, count(distinct left(name,2))/count(*) as sel2, count(distinct left(name,3))/count(*) as sel3, count(distinct left(name,4))/count(*) as sel4 from music; +--------+--------+--------+--------+ | sel1 | sel2 | sel3 | sel4 | +--------+--------+--------+--------+ | 0.3889 | 0.5000 | 0.5000 | 0.5000 | +--------+--------+--------+--------+
4)、可以看到当前缀长度为2是已经接近完整列索引选择性,添加前缀索引
1 2 3 4 5 6 7 8 9 10
alter table music add index music_index(name(2)); Query OK, 0 rows affected (0.06 sec) Records: 0 Duplicates: 0 Warnings: 0
show index from music; +-------+------------+-------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | +-------+------------+-------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ | music | 1 | music_index | 1 | name | A | 9 | 2 | NULL | YES | BTREE | | | +-------+------------+-------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
5)、查询索引是否被正常应用:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
select * from music where name like 's%'; +------------------+ | name | +------------------+ | Scarborough Fair | | Scarborough Fair | | Shape of You | | Shape of You | +------------------+ 4 rows in set (0.07 sec)
explain select * from music where name like 's%'; +----+-------------+-------+------------+-------+---------------+-------------+---------+------+------+----------+-------------+ | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+-------+------------+-------+---------------+-------------+---------+------+------+----------+-------------+ | 1 | SIMPLE | music | NULL | range | music_index | music_index | 11 | NULL | 4 | 100.00 | Using where | +----+-------------+-------+------------+-------+---------------+-------------+---------+------+------+----------+-------------+ 1 row in set, 1 warning (0.00 sec)
mysqladmin -uroot -p12345678 ext | grep Innodb_buffer_pool_reads mysqladmin: [Warning] Using a password on the command line interface can be insecure. | Innodb_buffer_pool_reads | 31763701 |
1 2 3
mysqladmin -uroot -p12345678 ext | grep Innodb_buffer_pool_read_requests mysqladmin: [Warning] Using a password on the command line interface can be insecure. | Innodb_buffer_pool_read_requests | 866018530 |
如果想要查看多次的取值,并计算间隔的差值(-i 1间隔为1s)(-r 获取前后两个值之间的差值)
1 2 3 4 5 6 7
mysqladmin -uroot -p12345678 -ri1 ext | grep Innodb_buffer_pool_reads mysqladmin: [Warning] Using a password on the command line interface can be insecure. | Innodb_buffer_pool_reads | 31763701 | | Innodb_buffer_pool_reads | 0 | | Innodb_buffer_pool_reads | 0 | | Innodb_buffer_pool_reads | 0 | | Innodb_buffer_pool_reads | 0 |
1 2 3 4 5 6 7 8 9
mysqladmin -uroot -p12345678 -ri1 ext | grep Innodb_buffer_pool_read_requests mysqladmin: [Warning] Using a password on the command line interface can be insecure. | Innodb_buffer_pool_read_requests | 866018530 | | Innodb_buffer_pool_read_requests | 0 | | Innodb_buffer_pool_read_requests | 0 | | Innodb_buffer_pool_read_requests | 0 | | Innodb_buffer_pool_read_requests | 0 | | Innodb_buffer_pool_read_requests | 0 | | Innodb_buffer_pool_read_requests | 0 |
cd prometheus-2.3.2.linux-amd64/ cat prometheus.yml # my global config global: scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute. evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute. # scrape_timeout is set to the global default (10s).
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'. rule_files: # - "first_rules.yml" # - "second_rules.yml"
# A scrape configuration containing exactly one endpoint to scrape: # Here it's Prometheus itself. scrape_configs: # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config. - job_name: 'prometheus'
# metrics_path defaults to '/metrics' # scheme defaults to 'http'.
wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.11.0/mysqld_exporter-0.11.0.linux-amd64.tar.gz tar -zxvf mysqld_exporter-0.11.0.linux-amd64.tar.gz cd mysqld_exporter-0.11.0.linux-amd64/
git clone git@github.com:dcu/mongodb_exporter.git $GOPATH/src/github.com/dcu/mongodb_exporter cd $GOPATH/src/github.com/dcu/mongodb_exporter make build