标签:修复 3.1 rds 表锁 oba 磁盘存储 线程 tran 介绍
mysql> show engines;
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| Engine | Support | Comment | Transactions | XA | Savepoints |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| CSV | YES | CSV storage engine | NO | NO | NO |
| MRG_MYISAM | YES | Collection of identical MyISAM tables | NO | NO | NO |
| MyISAM | YES | MyISAM storage engine | NO | NO | NO |
| BLACKHOLE | YES | /dev/null storage engine (anything you write to it disappears) | NO | NO | NO |
| InnoDB | DEFAULT | Supports transactions, row-level locking, and foreign keys | YES | YES | YES |
| PERFORMANCE_SCHEMA | YES | Performance Schema | NO | NO | NO |
| ARCHIVE | YES | Archive storage engine | NO | NO | NO |
| MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO |
| FEDERATED | NO | Federated MySQL storage engine | NULL | NULL | NULL |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
9 rows in set (0.00 sec)
用来处理数据库的相关CRUD操作
每个数据库都有存储引擎,只是MySQL比较强调存储引擎的概念。
InnoDB
-- 推荐;其他引擎已经体停止维护和开发Spider
第三方存储引擎在特定场合下比较适合,除此之外,都应该使用InnoDB
MY
开头的基本都是MyISAM的表
不是
MyISAM的优点,也不是存在的原因frm
表结构文件MYI
索引文件MYD
数据文件
MYI
中的叶子节点,指向MYD
中的数据页lock table sysbench.test_log_copy read
再修复mysql> show create table test_log_copy\G;
*************************** 1. row ***************************
Table: test_log_copy
Create Table: CREATE TABLE `test_log_copy` (
`scenario` varchar(30) NOT NULL DEFAULT ‘‘ COMMENT ‘测试场景‘,
`server_name` varchar(15) NOT NULL COMMENT ‘主机名‘,
`test_type` varchar(15) NOT NULL COMMENT ‘read-only,read-write,insert等‘,
`sb_threads` int(11) NOT NULL DEFAULT ‘0‘ COMMENT ‘sysbench 测试线程‘,
`create_time` datetime DEFAULT NULL COMMENT ‘开始时间‘,
`done_time` datetime DEFAULT NULL COMMENT ‘完成时间‘,
`server_load` decimal(12,2) NOT NULL DEFAULT ‘0.00‘ COMMENT ‘以当前线程测试完后立刻记录15分钟负载值‘,
`request_read` int(11) NOT NULL DEFAULT ‘0‘,
`request_write` int(11) NOT NULL DEFAULT ‘0‘,
`transactions_per_second` decimal(12,2) NOT NULL DEFAULT ‘0.00‘ COMMENT ‘QPS‘,
`request_per_second` decimal(12,2) NOT NULL DEFAULT ‘0.00‘ COMMENT ‘TPS‘,
`95_pct_time` decimal(12,2) NOT NULL DEFAULT ‘0.00‘ COMMENT ‘单位毫秒‘,
KEY `createtime` (`create_time`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8
1 row in set (0.00 sec)
ERROR:
No query specified
[root@localhost-m(252) /r2/soft/dbtest/mysql-5.7.18/mysqldata]# myisamchk sysbench/test_log_copy.MYI
Checking MyISAM file: sysbench/test_log_copy.MYI
Data records: 60 Deleted blocks: 0
- check file-size
- check record delete-chain
- check key delete-chain
- check index reference
- check data record references index: 1
- check record links
myisamchk
通过扫描MYD文件来重建MYI文件;如果MYD文件中某条记录有问题,将跳过该记录
千万不要用Memory存储引擎去做缓存(Cache)
, 性能上不及Redis和Memcahced不能禁用
,当涉及内部排序操作的临时表时,使用该存储引擎
max_heap_table_size
决定使用内存的大小,默认时16M
tmpdir
)mysql> show global status like "%tmp%tables";
+-------------------------+-------+
| Variable_name | Value |
+-------------------------+-------+
| Created_tmp_disk_tables | 673 | -- 内存放不下,转成磁盘存储的数量,如果过大,考虑增大内存参数
| Created_tmp_tables | 6455 | -- 创建临时表的数量
+-------------------------+-------+
2 rows in set (0.00 sec)
mysql> show variables like "tmp%";
+----------------+----------------------------------------+
| Variable_name | Value |
+----------------+----------------------------------------+
| tmp_table_size | 33554432 |
| tmpdir | /r2/soft/dbtest/mysql-5.7.18/mysqldata | -- memory转成磁盘存储的路径
+----------------+----------------------------------------+
2 rows in set (0.00 sec)
mysql> show create table User\G
*************************** 1. row ***************************
Table: User
Create Table: CREATE TABLE `User` (
`id` int(11) NOT NULL,
`name` varchar(128) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `name` (`name`) USING HASH -- 对这个字段使用USING HASH,创建hash索引
) ENGINE=MEMORY DEFAULT CHARSET=utf8
1 row in set (0.00 sec)
BLOB
和TEXT
类型frm
表结构CSV
数据文件CSM
元数据信息文件
必须是NOT NULL
属性my.cnf
的[mysqld]
标签下添加 federated
FederatedX
支持scheme://user_name[:password]@host_name[:port_num]/db_name/tbl_name
CONNECTION=‘mysql://username:password@hostname:port/database/tablename‘
CREATE TABLE `test001` (
`scenario` varchar(30) NOT NULL DEFAULT ‘‘ COMMENT ‘测试场景‘,
`server_name` varchar(15) NOT NULL COMMENT ‘主机名‘,
`test_type` varchar(15) NOT NULL COMMENT ‘read-only,read-write,insert等‘,
`sb_threads` int(11) NOT NULL DEFAULT ‘0‘ COMMENT ‘sysbench 测试线程‘,
`create_time` datetime DEFAULT NULL COMMENT ‘开始时间‘,
`done_time` datetime DEFAULT NULL COMMENT ‘完成时间‘,
`server_load` decimal(12,2) NOT NULL DEFAULT ‘0.00‘ COMMENT ‘以当前线程测试完后立刻记录15分钟负载值‘,
`request_read` int(11) NOT NULL DEFAULT ‘0‘,
`request_write` int(11) NOT NULL DEFAULT ‘0‘,
`transactions_per_second` decimal(12,2) NOT NULL DEFAULT ‘0.00‘ COMMENT ‘QPS‘,
`request_per_second` decimal(12,2) NOT NULL DEFAULT ‘0.00‘ COMMENT ‘TPS‘,
`95_pct_time` decimal(12,2) NOT NULL DEFAULT ‘0.00‘ COMMENT ‘单位毫秒‘,
KEY `createtime` (`create_time`)
) ENGINE=FEDERATED DEFAULT CHARSET=utf8 CONNECTION=‘mysql://federated:123456@192.168.48.168:3306/sysbench/test_log‘;
mysql> create user federated@‘192.168.24.180‘ identified by ‘123456‘;
Query OK, 0 rows affected (0.00 sec)
mysql> grant select on sysbench.* to federated@‘192.168.24.180‘;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql> show grants for federated@‘192.168.24.180‘;
+--------------------------------------------------------------+
| Grants for federated@192.168.24.180 |
+--------------------------------------------------------------+
| GRANT USAGE ON *.* TO ‘federated‘@‘192.168.24.180‘ |
| GRANT SELECT ON `sysbench`.* TO ‘federated‘@‘192.168.24.180‘ |
+--------------------------------------------------------------+
2 rows in set (0.00 sec)
--终端A数据表为sysbench.test_log表
mysql> select scenario ,server_name, test_type,sb_threads,create_time,done_time ,server_load from sysbench.test_log limit 1;
+-------------------+-------------+------------+------------+---------------------+---------------------+-------------+
| scenario | server_name | test_type | sb_threads | create_time | done_time | server_load |
+-------------------+-------------+------------+------------+---------------------+---------------------+-------------+
| oltp_update_index | localhost | read-write | 2 | 2017-11-15 11:55:07 | 2017-11-15 12:45:18 | 1.56 |
+-------------------+-------------+------------+------------+---------------------+---------------------+-------------+
1 row in set (0.00 sec)
--测试账号可用
[root@proxy ~]# mysql -h192.168.48.168 -ufederated -p123456 -e "select scenario ,server_name, test_type,sb_threads,create_time,done_time ,server_load from sysbench.test_log limit 1;"
mysql: [Warning] Using a password on the command line interface can be insecure.
+-------------------+-------------+------------+------------+---------------------+---------------------+-------------+
| scenario | server_name | test_type | sb_threads | create_time | done_time | server_load |
+-------------------+-------------+------------+------------+---------------------+---------------------+-------------+
| oltp_update_index | localhost | read-write | 2 | 2017-11-15 11:55:07 | 2017-11-15 12:45:18 | 1.56 |
+-------------------+-------------+------------+------------+---------------------+---------------------+-------------+
(root@localhost) 13:21:28 [(none)]> show engines;
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| Engine | Support | Comment | Transactions | XA | Savepoints |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| MyISAM | YES | MyISAM storage engine | NO | NO | NO |
| CSV | YES | CSV storage engine | NO | NO | NO |
| PERFORMANCE_SCHEMA | YES | Performance Schema | NO | NO | NO |
| BLACKHOLE | YES | /dev/null storage engine (anything you write to it disappears) | NO | NO | NO |
| MRG_MYISAM | YES | Collection of identical MyISAM tables | NO | NO | NO |
| InnoDB | DEFAULT | Supports transactions, row-level locking, and foreign keys | YES | YES | YES |
| ARCHIVE | YES | Archive storage engine | NO | NO | NO |
| MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO |
| FEDERATED | NO | Federated MySQL storage engine | NULL | NULL | NULL | -- FEDERATED引擎没有启动
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
9 rows in set (0.00 sec)
[root@proxy ~]# cat /etc/my.cnf
# ... 省略 ...
[mysqld]
federated -- 新增的配置项,表示打开Federated引擎
# ... 省略 ...
--重启MySQL
[root@proxy ~]# /usr/local/mysql/support-files/mysql.server stop
Shutting down MySQL..... SUCCESS!
[root@proxy ~]# /usr/local/mysql/support-files/mysql.server start
Starting MySQL... SUCCESS!
(root@localhost) 13:23:28 [(none)]> show engines;
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| Engine | Support | Comment | Transactions | XA | Savepoints |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| CSV | YES | CSV storage engine | NO | NO | NO |
| MRG_MYISAM | YES | Collection of identical MyISAM tables | NO | NO | NO |
| MyISAM | YES | MyISAM storage engine | NO | NO | NO |
| BLACKHOLE | YES | /dev/null storage engine (anything you write to it disappears) | NO | NO | NO |
| InnoDB | DEFAULT | Supports transactions, row-level locking, and foreign keys | YES | YES | YES |
| PERFORMANCE_SCHEMA | YES | Performance Schema | NO | NO | NO |
| ARCHIVE | YES | Archive storage engine | NO | NO | NO |
| MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO |
| FEDERATED | YES | Federated MySQL storage engine | NO | NO | NO | -- 显示YES,表示federated引擎已经启用
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
9 rows in set (0.00 sec)
(gcdb@localhost) 13:47:40 [(none)]> create database federated; --创建federated库
Query OK, 1 row affected (0.00 sec)
(gcdb@localhost) 13:47:53 [(none)]> use federated;
Database changed
--创建test001库映射(终端A sysbench.test_log表)
(gcdb@localhost) 13:48:02 [federated]> CREATE TABLE `test001` (
-> `scenario` varchar(30) NOT NULL DEFAULT ‘‘ COMMENT ‘测试场景‘,
-> `server_name` varchar(15) NOT NULL COMMENT ‘主机名‘,
-> `test_type` varchar(15) NOT NULL COMMENT ‘read-only,read-write,insert等‘,
-> `sb_threads` int(11) NOT NULL DEFAULT ‘0‘ COMMENT ‘sysbench 测试线程‘,
-> `create_time` datetime DEFAULT NULL COMMENT ‘开始时间‘,
-> `done_time` datetime DEFAULT NULL COMMENT ‘完成时间‘,
-> `server_load` decimal(12,2) NOT NULL DEFAULT ‘0.00‘ COMMENT ‘以当前线程测试完后立刻记录15分钟负载值‘,
-> `request_read` int(11) NOT NULL DEFAULT ‘0‘,
-> `request_write` int(11) NOT NULL DEFAULT ‘0‘,
-> `transactions_per_second` decimal(12,2) NOT NULL DEFAULT ‘0.00‘ COMMENT ‘QPS‘,
-> `request_per_second` decimal(12,2) NOT NULL DEFAULT ‘0.00‘ COMMENT ‘TPS‘,
-> `95_pct_time` decimal(12,2) NOT NULL DEFAULT ‘0.00‘ COMMENT ‘单位毫秒‘,
-> KEY `createtime` (`create_time`)
-> ) ENGINE=federated connection=‘mysql://federated:123456@192.168.48.168:3306/sysbench/test_log‘;
Query OK, 0 rows affected (0.01 sec)
(gcdb@localhost) 15:26:15 [federated]> select scenario ,server_name, test_type,sb_threads,create_time,done_time ,server_load from test001 limit 1,10; --测试可以查到数据
+-------------------+-------------+------------+------------+---------------------+---------------------+-------------+
| scenario | server_name | test_type | sb_threads | create_time | done_time | server_load |
+-------------------+-------------+------------+------------+---------------------+---------------------+-------------+
| oltp_update_index | localhost | read-write | 4 | 2017-11-15 12:45:18 | 2017-11-15 13:35:33 | 1.03 |
| oltp_update_index | localhost | read-write | 8 | 2017-11-15 13:35:33 | 2017-11-15 14:25:40 | 0.93 |
| oltp_update_index | localhost | read-write | 16 | 2017-11-15 14:25:40 | 2017-11-15 15:15:40 | 1.30 |
| oltp_update_index | localhost | read-write | 24 | 2017-11-15 15:15:40 | 2017-11-15 16:04:40 | 1.66 |
| oltp_update_index | localhost | read-write | 32 | 2017-11-15 16:04:40 | 2017-11-15 16:46:26 | 2.09 |
| oltp_update_index | localhost | read-write | 64 | 2017-11-15 16:46:26 | 2017-11-15 17:26:17 | 2.64 |
| oltp_update_index | localhost | read-write | 96 | 2017-11-15 17:26:17 | 2017-11-15 18:06:47 | 1.90 |
| oltp_update_index | localhost | read-write | 128 | 2017-11-15 18:06:48 | 2017-11-15 18:47:24 | 2.52 |
| oltp_update_index | localhost | read-write | 196 | 2017-11-15 18:47:24 | 2017-11-15 19:27:57 | 2.44 |
| oltp_update_index | localhost | read-write | 2 | 2017-11-16 03:48:32 | 2017-11-16 04:38:32 | 5.49 |
+-------------------+-------------+------------+------------+---------------------+---------------------+-------------+
10 rows in set (0.01 sec)
-- 由于只有select权限,无法对该`federated`.`test001`表进行insert操作
(gcdb@localhost) 15:27:09 [federated]> INSERT INTO `federated`.`test001` (
-> `scenario`,
-> `server_name`,
-> `test_type`,
-> `sb_threads`,
-> `create_time`,
-> `done_time`,
-> `server_load`,
-> `request_read`,
-> `request_write`,
-> `transactions_per_second`,
-> `request_per_second`,
-> `95_pct_time`
-> )
-> VALUES
-> (
-> ‘扯淡计划‘,
-> ‘拯救小黑羊‘,
-> ‘read-write‘,
-> ‘2‘,
-> ‘2017-11-24 11:55:07‘,
-> ‘2017-11-24 12:45:18‘,
-> ‘1.00‘,
-> ‘0‘,
-> ‘699408‘,
-> ‘290.10‘,
-> ‘290.10‘,
-> ‘0.78‘
-> );
ERROR 1296 (HY000): Got error 10000 ‘Error on remote system: 1142: INSERT command denied to user ‘federated‘@‘192.168.24.180‘ for table ‘‘ from FEDERATED
标签:修复 3.1 rds 表锁 oba 磁盘存储 线程 tran 介绍
原文地址:http://www.cnblogs.com/gczheng/p/7890294.html