MySQL复制: 5.1.48指向5.5.18后出现的错误

一个数据库,老主库 A (5.1.48) 老主库B (5.1.48) 新主库C (5.5.18)

 

当把B指向C ,start slave,出现复制错误

Error ‘Character set ‘#45′ is not a compiled character set and is not specified in the ‘/u01/mysql/share/mysql/charsets/Index.xml’ file’ on query. Default database

 

原因是新版本的字符集比5.1.48多了,所以5.1.48认不到Character set ‘#45′

 

而在MySQL的官方手册里面,也说明了不建议旧版本复制新版本  (http://dev.mysql.com/doc/refman/5.5/en/replication-compatibility.html

Replication from newer masters to older slaves may be possible, but is generally not supported
 
也曾经有外国友人报bug,但其实不是bug http://bugs.mysql.com/bug.php?id=50655
 
最后的解决办法 重新启动一个D(5.5.18)版本,作为新备库


 
Posted in Linux | Tagged | 2 Comments

MySQL语法: group by的默认顺序

飞影 17:31:25
select * from (select * from ….. order by a desc, b desc, c desc) group by a desc

哥,像我上面那个语句, 子select里面对a,b,c进行了ordery排序
外面的根据aa进行了group by
aa重复的数据里面,a和b是相同的,就c不同
这个sql会打乱先a和b的orderby顺序结果吗??

一开始看到这个问题,还真没什么头绪,于是搞了一个简单的测试case来验证

create table test_desc(a int ,b int, c int);
insert into test_desc values(1,2,3), (2,3,4),(5,6,7) ;

root@test 06:33:43>select * from (select * from test_desc order by a desc, b desc, c desc) as aa group by a ;
+——+——+——+
| a | b | c |
+——+——+——+
| 1 | 2 | 3 |
| 2 | 3 | 4 |
| 5 | 6 | 7 |
+——+——+——+
3 rows in set (0.00 sec)

从这里可以看到 group by a字段后,输出的结果是默认asc的

飞影同学需要的是desc 效果,直接 group by a desc;

root@test 06:35:36>select * from (select * from test_desc order by a desc, b desc, c desc) as aa group by a desc;
+——+——+——+
| a | b | c |
+——+——+——+
| 5 | 6 | 7 |
| 2 | 3 | 4 |
| 1 | 2 | 3 |
+——+——+——+
3 rows in set (0.00 sec)

Posted in Linux | Tagged | Leave a comment

MySQL性能:一个非典型的MySQL性能问题

今天线上某核心数据库发生一起非典型的数据库性能问题

数据库相关参数如下

Var : port[3306] read_only[OFF] version[5.5.18-log]

binlog_format[ROW] max_binlog_cache_size[2G] max_binlog_size[500M]
max_connect_errors[50000] max_connections[2100] max_user_connections[2000]
open_files_limit[131070] sync_binlog[0] table_definition_cache[2048]
table_open_cache[2048] thread_cache_size[512]

innodb_adaptive_flushing[ON] innodb_adaptive_hash_index[ON] innodb_buffer_pool_instances[8]
innodb_buffer_pool_size[17G] innodb_file_per_table[ON] innodb_flush_log_at_trx_commit[2]
innodb_flush_method[O_DIRECT] innodb_io_capacity[1000] innodb_lock_wait_timeout[100]
innodb_log_buffer_size[200M] innodb_log_file_size[1000M] innodb_log_files_in_group[4]
innodb_max_dirty_pages_pct[60] innodb_open_files[60000] innodb_read_io_threads[8]
innodb_stats_on_metadata[ON] innodb_thread_concurrency[32] innodb_write_io_threads[8]

17:05分 MySQL 数据库 threads_running出现飙升

NewImage

与此同时,17:05:30  innodb_row_lock_waits也发生飙升

NewImage

数据库load也在差不多的时间点发生飙升

NewImage

数据库QPS在对应的时间点12-20 17:05发生QPS 下降

NewImage

数据库链接在17点06分到17点07分之间,链接数量发生飙升

NewImage

链接升高的差不多时间点,从InnoDB Buffer Pool的读请求也开始飙升

NewImage

Threads_running 情况

NewImage

slow quires也在17:07的时候瞬间飙升

NewImage

 

当这台机器出现性能波动的时候,淘宝DBA组的N个DBA一起上阵分析到底是什么性能问题,当时候集中在三个观点

1. 并发更新导致数据库hang(因为有lock…)

2.InnoDB 在做checkpoint flush  (因为从监控系统看,更新也被堵住了)

3. 因为slowlog里面有事务提交的commit(由于sync_binlog=0,怀疑OS 刷cache的内存到binlog文件,影响事务响应时间,把sync_binlog=0修改为sync_binlog=100)

 

Posted in Linux | Tagged | Leave a comment

Have a on-site talk with InnoDB Team

Today , the InnoDB team takes a visit to Alibaba Group.  

Alibaba Group has serval sub company .  For example , Alipay.com ,Taobao.com and Tmall.com, these company have a huge MySQL/InnoDB Database Cluster.

Alipay.com , it is the biggest  third-party online payment platform in China. It has over 700 millions users, and every day, over serval  million user login alipay.com  and do payment business.  

Alipay.com has more accounts thant Paypal.com, the reasons are that Chinses economy is booming and the benefits of a large population.

Alipay.com has over serval hundred MySQL instances, including MySQL 5.1.48 and Percona Server 5.5.X. In Alipay.com

Taobao.com , it is the  most famous  C2C online shopping website in China Mainland. Also , Taobao.com is the 14th in the 1000 most-visited sites on Google Ranking  .  Today , I made a presentation of MySQL In Alibaba Group, including MySQL Version, Sharding solutions, and Hardware solution . 

MySQL Version

In Taobao.com , we have over 2000 MySQL instances, including MySQL 5.1.48+InnoDB Plugin 1.0.8, Percona Server 5.5.18 . Until right now , we still not ready to deploy MySQL Server 5.6 to online production environment. But we are expecting that we can use the online DDL features in MySQL 5.6 . Because that  when we add index / add column to a online InnoDB table , it will lock the write request until the DDL is done.

Sharding solutions.

We don’t use the partitions function in MySQL. We just use the logical shading solution. For example ,  we have a InnoDB table to store the user information , and one important thing is that the user_id is a special column, we use the formula to shard data into different table  – ” user_id % 1024″ , and it can tell us where is in . we also have 16 databases to store 1024 tables. so , the solution for how to locate the target database , just use  (user_id %1024)/64.


Hardware solutions to MySQL server. 

SSD+SAS

In SSD PC server, we set up mutil-instances in this kind PC server , in order to maximum the performance , as you kown, MySQL still has the code which was written over 10 years ago, and these code was written in low-performance machine. So we use cgroup technology to control IO resources and memory resources.  SSD hardware solutions for some important application that have heavy write request . 

FusionIO Card+Flashcache+SAS

this solution works for some important applications , like user information MySQL cluster. Because this application is heavy read , and we need to afford the cache system may crash, and handler the sudden high read traffic.

SAS 

SAS solution , we also setup up RAID 10 to ensure the data safely , but right now , we deploy the SSD server to replace the SAS server.

SATA



 

Posted in MySQL | Tagged | 2 Comments

MySQL 5.5 Reset Slave

Before 2012, we also deployed MySQL 5.1.48 +InnoDB Plugin 1.0.9 to onlie application.  Now in 2012, we begin to use MySQL 5.5 .

There is different between 5.1 and 5.5  in reseting slave .

In MySQL 5.1 , we can reset slave by

change master to master_host='';

 

But In MySQL 5.5.18(Percona version), it won’t work.

root@(none) 10:55:43>change master to master_host='';
ERROR 1210 (HY000): Incorrect arguments to MASTER_HOST
 
The Method for 5.5 likes this 
1. reset slave;
2. restart MySQL Server. 
Posted in MySQL | 3 Comments

从多个binlog找到某条记录的修改历史

需要从binlog里面找一条6月15创建的记录的修改历史,从6月15日到6月20日,一共有几十个mysql 的binlog,如果是人工操作,需要操作几十次,我们可以用shell来加快处理的速度

来到mysqlbinlog的目录 /u01/mysql/log,先列出最近5天被访问过的binlog文件列表

$find . -atime  -5   -print  | grep mysql-bin.00 | xargs ls -lh
-rw-rw---- 1 mysql dba 501M Jun 14 18:04 ./mysql-bin.001090
-rw-rw---- 1 mysql dba 501M Jun 15 01:12 ./mysql-bin.001091
-rw-rw---- 1 mysql dba 501M Jun 15 02:10 ./mysql-bin.001092
-rw-rw---- 1 mysql dba 501M Jun 15 04:05 ./mysql-bin.001093
-rw-rw---- 1 mysql dba 137M Jun 15 04:36 ./mysql-bin.001094
-rw-rw---- 1 mysql dba 501M Jun 15 11:57 ./mysql-bin.001095
-rw-rw---- 1 mysql dba 501M Jun 15 19:00 ./mysql-bin.001096
-rw-rw---- 1 mysql dba 501M Jun 16 02:00 ./mysql-bin.001097
-rw-rw---- 1 mysql dba 501M Jun 16 02:11 ./mysql-bin.001098
-rw-rw---- 1 mysql dba 489M Jun 16 04:32 ./mysql-bin.001099
-rw-rw---- 1 mysql dba 501M Jun 16 10:14 ./mysql-bin.001100
-rw-rw---- 1 mysql dba 501M Jun 16 19:42 ./mysql-bin.001101
-rw-rw---- 1 mysql dba 501M Jun 17 02:02 ./mysql-bin.001102
-rw-rw---- 1 mysql dba 501M Jun 17 02:13 ./mysql-bin.001103
-rw-rw---- 1 mysql dba 451M Jun 17 04:35 ./mysql-bin.001104
-rw-rw---- 1 mysql dba 501M Jun 17 13:50 ./mysql-bin.001105
-rw-rw---- 1 mysql dba 501M Jun 18 01:09 ./mysql-bin.001106
-rw-rw---- 1 mysql dba 501M Jun 18 02:09 ./mysql-bin.001107
-rw-rw---- 1 mysql dba 501M Jun 18 04:00 ./mysql-bin.001108
-rw-rw---- 1 mysql dba 115M Jun 18 04:31 ./mysql-bin.001109
-rw-rw---- 1 mysql dba 501M Jun 18 13:16 ./mysql-bin.001110
-rw-rw---- 1 mysql dba 501M Jun 18 21:28 ./mysql-bin.001111
-rw-rw---- 1 mysql dba 501M Jun 19 02:04 ./mysql-bin.001112
-rw-rw---- 1 mysql dba 501M Jun 19 02:36 ./mysql-bin.001113
-rw-rw---- 1 mysql dba 386M Jun 19 04:35 ./mysql-bin.001114
-rw-rw---- 1 mysql dba 501M Jun 19 12:29 ./mysql-bin.001115
-rw-rw---- 1 mysql dba 501M Jun 19 20:42 ./mysql-bin.001116
-rw-rw---- 1 mysql dba 501M Jun 20 02:03 ./mysql-bin.001117
-rw-rw---- 1 mysql dba 501M Jun 20 02:15 ./mysql-bin.001118
-rw-rw---- 1 mysql dba 373M Jun 20 04:31 ./mysql-bin.001119
-rw-rw---- 1 mysql dba 474M Jun 20 11:01 ./mysql-bin.001120
 
然后我们弄到一个for循环里面自动做binlog解析,最后的脚本是这样的 
export.sh
cd /u01/mysql/log/list=`find . -atime -5 -print | grep mysql-bin.00`
for i in $list; do
    echo $i;
    mysqlbinlog --no-defaults /u01/mysql/log/$i > /u01/mysql/restore_test/$i.log
    cat $i.log | grep update | grep keyword > cat_$i.log
done

 

后面执行一下sh export.sh ,根据cat_x的文件大小,可以得到对应的修改记录的时间属性等。如果以后再出现这种从多个binlog里面找某一条记录的时候,可以用这种办法试试

 

如果你有更好的办法,烦请告诉我微笑

Posted in MySQL | Leave a comment

Inforbright 设置使用MySQL查询路径

Infobright自带了查询优化器,从它的总体架构图可以看到,既有infobright的查询优化器,也有MySQL的查询优化器

 

今天 逸轩-TB 在使用ib进行一个较为复杂的查询的时候,遇到了这样一个错误

Query error #5: The query includes syntax that is not supported by the Infobright Optimizer. Either restructure the query with supported syntax, or enable the MySQL Query Path in the brighthouse.ini file to execute the query with reduced performance.

 

告错信息大意是 ,Infobright的优化器不支持某种查询语法,解决方案是 重构查询语句,或者是激活MySQL的查询路径

 

后来我尝试做了explain ,发现是可以跑explain的分析。

 

在brighthouse.ini里面,有AllowMySQLQueryPath的选项,默认为0,而这个参数是不能动态修改的

mysql> set global brighthouse_ini_allowmysqlquerypath=0;
ERROR 1238 (HY000): Variable ‘brighthouse_ini_allowmysqlquerypath’ is a read only variable

 

解决步骤

1.修改AllowMySQLQueryPath=1

2.重启mysql

3.再跑这个select语句,发现可以跑起来了 微笑

Posted in Linux | Leave a comment

Find out the difference between Com_Select and InnoDB_rows_read

This morning  one MySQL cluster ( 4 Master ,4 Slave) , one mysql server ‘s response time raises up.

The raid config of the server

Adapter 0 -- Virtual Drive Information:
Virtual Drive: 0 (Target Id: 0)
Name                :
RAID Level          : Primary-1, Secondary-0, RAID Level Qualifier-0
Size                : 99.999 GB
State               : Optimal
Strip Size          : 64 KB
Number Of Drives per span:2
Span Depth          : 6
Default Cache Policy: WriteBack, ReadAheadNone, Direct, Write Cache OK if Bad BBU
Current Cache Policy: WriteBack, ReadAheadNone, Direct, Write Cache OK if Bad BBU
Access Policy       : Read/Write
Disk Cache Policy   : Disabled
Encryption Type     : None

Virtual Drive: 1 (Target Id: 1)
Name                :
RAID Level          : Primary-1, Secondary-0, RAID Level Qualifier-0
Size                : 1.533 TB
State               : Optimal
Strip Size          : 64 KB
Number Of Drives per span:2
Span Depth          : 6
Default Cache Policy: WriteBack, ReadAheadNone, Direct, Write Cache OK if Bad BBU
Current Cache Policy: WriteBack, ReadAheadNone, Direct, Write Cache OK if Bad BBU
Access Policy       : Read/Write
Disk Cache Policy   : Disabled
Encryption Type     : None

The pressure tends of this server

image

The first trend is MySQL Com_select , the second trend picture is MySQL InnoDB_rows_read. You can find out that the InnoDB_rows_read is larger than the counter of Com_Select.

At the beginng , it makes me confused  that  why the result of innodb_rows_read is bigger than com_select.

And what’s more , iostat tells me that disk is very busy and the avg response time is over 5ms. Yes, Response time is not ideal.

image

Finally , i observe the running sql in MySQL.

I found that a large number of this  sql is running

SELECT id, user_id, subscribe_id, twoway, group_ids, gmt_create, gmt_modified
FROM table_0485
WHERE user_id =376297445
ORDER BY gmt_create DESC
LIMIT 0 , 2000

What’s the problem of this sql?

1. It is query 2000 rows from InnoDB, if we have 100 sql like this is running, the innodb_rows_read = 100*2000;

2. the column user_id is not necessary to select once again, because we have post the user_id . We can redure the traffic after remove user_id,just like this “SELECT id, subscribe_id, twoway, group_ids, gmt_create, gmt_modified ”

 

So , return to our topic “Find out the difference between Com_Select and InnoDB_rows_read

Right, if we have some query that need over thounds row, although the com_select is little, but the InnoDB_rows_read may is large.

Posted in MySQL | Tagged | Leave a comment

[InnoDB]Truncate table difference between InnoDB build-in and InnoDB Plugin-in

MySQL(5.1.37) InnoDB Build-in

root@(none) 04:55:17> SHOW PLUGINS;
+------------+--------+----------------+---------+---------+
| Name       | Status | Type           | Library | License |
+------------+--------+----------------+---------+---------+
| binlog     | ACTIVE | STORAGE ENGINE | NULL    | GPL     |
| partition  | ACTIVE | STORAGE ENGINE | NULL    | GPL     |
| CSV        | ACTIVE | STORAGE ENGINE | NULL    | GPL     |
| MEMORY     | ACTIVE | STORAGE ENGINE | NULL    | GPL     |
| InnoDB     | ACTIVE | STORAGE ENGINE | NULL    | GPL     |
| MyISAM     | ACTIVE | STORAGE ENGINE | NULL    | GPL     |
| MRG_MYISAM | ACTIVE | STORAGE ENGINE | NULL    | GPL     |
+------------+--------+----------------+---------+---------+
7 rows in set (0.00 sec)

How Can we certify we using InnoDB Plugin, you just need run “show plugins” ,if you see the result like above, it is.

When we truncate one table .

[MM-Writable@mysqldb /u01/mysql/data/db_02]
$du -sh db.ibd
773M    db.ibd

root@db_02 05:08:55>select count(*) from db;
+----------+
| count(*) |
+----------+
|  1410879 |
+----------+
1 row in set (0.38 sec) 

root@db_02 05:08:59>truncate table db;
Query OK, 0 rows affected (0.08 sec) 

root@db_02 05:09:05>select count(*) from db;
+----------+
| count(*) |
+----------+
|        0 |
+----------+
1 row in set (0.00 sec)

 

After we truncate the table “db”, we found that the total number of the table is zero. But the file is still use the space

$du -sh * | grep db

12K     db.frm
773M    db.ibd

Finally , how can we withdraw the space??? It is easily we just run “ alter table db engine=innodb;”;

root@snsfa_02 05:13:10>alter table sns_universal_relations_0064 engine=innodb;
Query OK, 0 rows affected (0.92 sec)
Records: 0  Duplicates: 0  Warnings: 0 

root@snsfa_02 05:13:17>exit
Bye 

[MM-Writable@my130.cm4 /u01/mysql/data/snsfa_02]
$du -sh * | grep sns_universal_relations_0064
12K     sns_universal_relations_0064.frm
132K    sns_universal_relations_0064.ibd

 

 

InnoDB Plugin-in

root@(none) 04:55:17> SHOW PLUGINS; 

| InnoDB                         | ACTIVE | STORAGE ENGINE     | NULL             | GPL     |
| INNODB_RSEG                    | ACTIVE | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_TRX                     | ACTIVE | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_LOCKS                   | ACTIVE | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_LOCK_WAITS              | ACTIVE | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_CMP                     | ACTIVE | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_CMP_RESET               | ACTIVE | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_CMPMEM                  | ACTIVE | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_CMPMEM_RESET            | ACTIVE | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_SYS_TABLES              | ACTIVE | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_SYS_TABLESTATS          | ACTIVE | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_SYS_INDEXES             | ACTIVE | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_SYS_COLUMNS             | ACTIVE | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_SYS_FIELDS              | ACTIVE | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_SYS_FOREIGN             | ACTIVE | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_SYS_FOREIGN_COLS        | ACTIVE | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_SYS_STATS               | ACTIVE | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_TABLE_STATS             | ACTIVE | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_INDEX_STATS             | ACTIVE | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_BUFFER_POOL_PAGES       | ACTIVE | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_BUFFER_POOL_PAGES_INDEX | ACTIVE | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_BUFFER_POOL_PAGES_BLOB  | ACTIVE | INFORMATION SCHEMA | NULL             | GPL     |
| XTRADB_ADMIN_COMMAND           | ACTIVE | INFORMATION SCHEMA | NULL             | GPL   

When you are using InnoDB Plugin, it is actually Effective for your work.

When you  truncate table,  InnoDB Plugin would help you immediately empty the space.!

 

Reference http://dev.mysql.com/doc/refman/5.1/en/replacing-builtin-innodb.html

Posted in MySQL | Tagged | Leave a comment

shell脚本批量操作多个表

分布式情况下很多分表,比如user_0000到 user_0511 。需要一个简便的批量操作方法。

例如 truncate table . alter table engine=innodb; drop tale等

 

脚本非常简单

 

list=`echo "show tables like ‘%user%’ " | mysql -uroot test -N `
for i in  $list;do
echo "alter table test.$i engine=innodb;" | mysql -uroot test
done

Posted in MySQL | Tagged | Leave a comment