[mysqldumpslow 报错] Died at /usr/local/mysql/bin/mysqldumpslow line 161, <> chunk 236.


mysqldumpslow报错:Died at /usr/local/mysql/bin/mysqldumpslow line 161, <> chunk 236.

总结:是因为top数目太多了,mysqldumpslow遍历不过来的缘故。

/usr/local/mysql/bin/mysqldumpslow -s -t 15 /root/db01-102-slow.log


1,把r去掉试试,还是报错,参数不识别。

[root@slave ]# /usr/local/mysql/bin/mysqldumpslow -s -t 15 /root/db01-102-slow.log 

Reading mysql slow query log from 15 /root/db01-102-slow.log
Can't open 15: 没有那个文件或目录 at /usr/local/mysql/bin/mysqldumpslow line 91.
Count: 22  Time=9.61s (211s)  Lock=0.00s (0s)  Rows=1.0 (22), [dubbo]@2hosts
  select count(*)
  from coupon_lot
  left join coupon 
  on coupon.coupon_lot_id = coupon_lot.coupon_lot_id
  LEFT JOIN brand
  ON brand.brand_id=coupon_lot.brand_id
  LEFT JOIN product_category
  on product_category.category_id=coupon_lot.category_id

Count: 177  Time=1.40s (247s)  Lock=0.00s (0s)  Rows=1.0 (177), [dubbo]@2hosts
  select count(*) from user_info
  LEFT JOIN system_region a
  ON province_id =a.region_id
  LEFT JOIN system_region b
  ON city_id = b.region_id
  LEFT JOIN system_region c
  ON district_id = c.region_id

Count: 22  Time=13.20s (290s)  Lock=0.00s (0s)  Rows=10.0 (220), [dubbo]@2hosts
  select 
  coupon_id, coupon_lot.coupon_lot_id, coupon_lot.remark,
  coupon.code,  coupon_lot.coupon_type, coupon.state,
  coupon_lot.ckey, coupon_lot.cvalue, coupon_lot.discount, coupon_lot.type, coupon_lot.channel, 
  coupon_lot.is_reusable, coupon_lot.start_datetime,
  coupon_lot.end_datetime, coupon_lot.create_datetime, coupon.update_datetime ,coupon_lot.department,
  coupon_lot.state as couponLotState, coupon_lot.create_operator,coupon_lot.coupon_category,
  coupon_lot.pdt_code,brand.brand_name,product_category.category_name
  from coupon_lot
  left join coupon 
  on coupon.coupon_lot_id = coupon_lot.coupon_lot_id
  LEFT JOIN brand
  ON brand.brand_id=coupon_lot.brand_id
  LEFT JOIN product_category
  on product_category.category_id=coupon_lot.category_id
  group by coupon_lot.coupon_lot_id
  order by coupon_lot.create_datetime DESC
  limit N,N

Count: 8  Time=1.09s (8s)  Lock=0.00s (0s)  Rows=10.0 (80), [dubbo]@2hosts
  select 
  return_sn,  relating_order_sn, return_from,  oi.order_out_sn ,
  add_time , return_type, 
  return_pay, ui.usename as userName, return_consignee, return_goods_count ,
  return_total_fee, total_paid, 
  return_desc, return_order_status,  return_pay_status ,
  return_shipping_status, order_return.lock_operator, order_return.return_invoice_no
  from order_return  LEFT JOIN   order_info oi
  on order_return.relating_order_sn = oi.order_sn 
  left join user_info ui on oi.user_id = ui.user_id
  left join order_payment on order_payment.order_sn = oi.order_sn
  order by order_return.add_time DESC
  limit N,N

Count: 1  Time=1.00s (1s)  Lock=0.00s (0s)  Rows=1.0 (1), root[root]@localhost
  select sleep(N)

Count: 1  Time=1.13s (1s)  Lock=0.00s (0s)  Rows=10.0 (10), [dubbo]@[xx]
  select 
  return_sn,  relating_order_sn, return_from,  oi.order_out_sn ,
  add_time , return_type, 
  return_pay, ui.usename as userName, return_consignee, return_goods_count ,
  return_total_fee, total_paid, 
  return_desc, return_order_status,  return_pay_status ,
  return_shipping_status, order_return.lock_operator, order_return.return_invoice_no
  from order_return  LEFT JOIN   order_info oi
  on order_return.relating_order_sn = oi.order_sn 
  left join user_info ui on oi.user_id = ui.user_id
  left join order_payment on order_payment.order_sn = oi.order_sn
  order by order_return.add_time DESC
  , oi.order_sn 
  limit N,N

Count: 5  Time=2.47s (12s)  Lock=0.00s (0s)  Rows=0.0 (0), [dubbo]@2hosts
  select
  user_id, usename, nickname, password, user_group_id, realname, gender, email, mobilephone, 
  birthday, province_id, city_id, district_id, marry, income, remarks, create_datetime, 
  active_state, verityEmail, verityPhone, credit, last_login, last_ip, is_locked, channel, 
  tag, union_partner_uuid, union_user_safekey, is_black, qq, weibo_id, verity_email_key, 
  verity_phone_key, verity_email_datetime, verity_phone_datetime, verity_question, 
  verity_answer, cps_code, cps_time_from, cps_time_to, cps_cookie, first_channel
  from user_info where mobilephone = 'S' and (channel is null or trim(channel) ='S')

2,查看下mysqldumpslow 使用参数,-s后面需要带参数的,看了西夏at比较合适

[root@db-master-2 ~]# /usr/local/mysql/bin/mysqldumpslow  --help
Usage: mysqldumpslow [ OPTS... ] [ LOGS... ]

Parse and summarize the MySQL slow query log. Options are

  --verbose    verbose
  --debug      debug
  --help       write this text to standard output

  -v           verbose
  -d           debug
  -s ORDER     what to sort by (al, at, ar, c, l, r, t), 'at' is default
                al: average lock time
                ar: average rows sent
                at: average query time
                 c: count
                 l: lock time
                 r: rows sent
                 t: query time  
  -r           reverse the sort order (largest last instead of first)
  -t NUM       just show the top n queries
  -a           don't abstract all numbers to N and strings to 'S'
  -n NUM       abstract numbers with at least n digits within names
  -g PATTERN   grep: only consider stmts that include this string
  -h HOSTNAME  hostname of db server for *-slow.log filename (can be wildcard),
               default is '*', i.e. match all
  -i NAME      name of server instance (if using mysql.server startup script)
  -l           don't subtract lock time from total time


3,在mysqldumpslow的-s后面加入 at参数试试: [root@slave ]# /usr/local/mysql/bin/mysqldumpslow -s at -t 15 /root/db01-102-slow.log

[root@db-master-2 ~]# /usr/local/mysql/bin/mysqldumpslow -s at -t 15 /root/db01-102-slow.log 
Reading mysql slow query log from /root/db01-102-slow.log
Count: 22  Time=13.20s (290s)  Lock=0.00s (0s)  Rows=10.0 (220), [dubbo]@2hosts
  select 
  coupon_id, coupon_lot.coupon_lot_id, coupon_lot.remark,
  coupon.code,  coupon_lot.coupon_type, coupon.state,
  coupon_lot.ckey, coupon_lot.cvalue, coupon_lot.discount, coupon_lot.type, coupon_lot.channel, 
  coupon_lot.is_reusable, coupon_lot.start_datetime,
  coupon_lot.end_datetime, coupon_lot.create_datetime, coupon.update_datetime ,coupon_lot.department,
  coupon_lot.state as couponLotState, coupon_lot.create_operator,coupon_lot.coupon_category,
  coupon_lot.pdt_code,brand.brand_name,product_category.category_name
  from coupon_lot
  left join coupon 
  on coupon.coupon_lot_id = coupon_lot.coupon_lot_id
  LEFT JOIN brand
  ON brand.brand_id=coupon_lot.brand_id
  LEFT JOIN product_category
  on product_category.category_id=coupon_lot.category_id
  group by coupon_lot.coupon_lot_id
  order by coupon_lot.create_datetime DESC
  limit N,N

Count: 22  Time=9.61s (211s)  Lock=0.00s (0s)  Rows=1.0 (22), [dubbo]@2hosts
  select count(*)
  from coupon_lot
  left join coupon 
  on coupon.coupon_lot_id = coupon_lot.coupon_lot_id
  LEFT JOIN brand
  ON brand.brand_id=coupon_lot.brand_id
  LEFT JOIN product_category
  on product_category.category_id=coupon_lot.category_id

Count: 5  Time=2.47s (12s)  Lock=0.00s (0s)  Rows=0.0 (0), [dubbo]@2hosts
  select
  user_id, usename, nickname, password, user_group_id, realname, gender, email, mobilephone, 
  birthday, province_id, city_id, district_id, marry, income, remarks, create_datetime, 
  active_state, verityEmail, verityPhone, credit, last_login, last_ip, is_locked, channel, 
  tag, union_partner_uuid, union_user_safekey, is_black, qq, weibo_id, verity_email_key, 
  verity_phone_key, verity_email_datetime, verity_phone_datetime, verity_question, 
  verity_answer, cps_code, cps_time_from, cps_time_to, cps_cookie, first_channel
  from user_info where mobilephone = 'S' and (channel is null or trim(channel) ='S')

Count: 177  Time=1.40s (247s)  Lock=0.00s (0s)  Rows=1.0 (177), [dubbo]@2hosts
  select count(*) from user_info
  LEFT JOIN system_region a
  ON province_id =a.region_id
  LEFT JOIN system_region b
  ON city_id = b.region_id
  LEFT JOIN system_region c
  ON district_id = c.region_id

Count: 1  Time=1.13s (1s)  Lock=0.00s (0s)  Rows=10.0 (10), [dubbo]@[10.10.3.8]
  select 
  return_sn,  relating_order_sn, return_from,  oi.order_out_sn ,
  add_time , return_type, 
  return_pay, ui.usename as userName, return_consignee, return_goods_count ,
  return_total_fee, total_paid, 
  return_desc, return_order_status,  return_pay_status ,
  return_shipping_status, order_return.lock_operator, order_return.return_invoice_no
  from order_return  LEFT JOIN   order_info oi
  on order_return.relating_order_sn = oi.order_sn 
  left join user_info ui on oi.user_id = ui.user_id
  left join order_payment on order_payment.order_sn = oi.order_sn
  order by order_return.add_time DESC
  , oi.order_sn 
  limit N,N

Count: 8  Time=1.09s (8s)  Lock=0.00s (0s)  Rows=10.0 (80), [dubbo]@2hosts
  select 
  return_sn,  relating_order_sn, return_from,  oi.order_out_sn ,
  add_time , return_type, 
  return_pay, ui.usename as userName, return_consignee, return_goods_count ,
  return_total_fee, total_paid, 
  return_desc, return_order_status,  return_pay_status ,
  return_shipping_status, order_return.lock_operator, order_return.return_invoice_no
  from order_return  LEFT JOIN   order_info oi
  on order_return.relating_order_sn = oi.order_sn 
  left join user_info ui on oi.user_id = ui.user_id
  left join order_payment on order_payment.order_sn = oi.order_sn
  order by order_return.add_time DESC
  limit N,N

Count: 1  Time=1.00s (1s)  Lock=0.00s (0s)  Rows=1.0 (1), root[root]@localhost
  select sleep(N)

Died at /usr/local/mysql/bin/mysqldumpslow line 161, <> chunk 236.
看到后面还是报错:Died at /usr/local/mysql/bin/mysqldumpslow line 161, <> chunk 236.

4,去看看/usr/local/mysql/bin/mysqldumpslow的第161行左右,到底是在操作什么脚本。

156 my @sorted = sort { $stmt{$b}->{$opt{s}} <=> $stmt{$a}->{$opt{s}} } keys %stmt;
157 @sorted = @sorted[0 .. $opt{t}-1] if $opt{t};
158 @sorted = reverse @sorted         if $opt{r};
159 
160 foreach (@sorted) {
161     my $v = $stmt{$_} || die;
162     my ($c, $t,$at, $l,$al, $r,$ar) = @{ $v }{qw(c t at l al r ar)};
163     my @users = keys %{$v->{users}};
164     my $user  = (@users==1) ? $users[0] : sprintf "%dusers",scalar @users;
165     my @hosts = keys %{$v->{hosts}};
166     my $host  = (@hosts==1) ? $hosts[0] : sprintf "%dhosts",scalar @hosts;
167     printf "Count: %d  Time=%.2fs (%ds)  Lock=%.2fs (%ds)  Rows=%.1f (%d), $user\@$host\n%s\n\n",
168             $c, $at,$t, $al,$l, $ar,$r, $_;
169 }
170 
171 sub usage {
172     my $str= shift;
看到主要是foreach (@sorted)遍历函数,也就是遍历到chunk 236的时候就died结束了,没有办法往下继续foreach了。因为以前写过代码,知道报错所在的这一行

 my $v = $stmt{$_} || die;
是遍历第一句,那么肯定是赋值语句,报错Died,chunk 236肯定是已经遍历到末尾没有数据了,看这个函数没有判断传入的参数是否为null的逻辑,所以当文件数据已经遍历完,但是命令还没有结束,所以继续遍历,遍历null的时候报错,所以进程中止了,解决办法就是做个限制不要遍历超过原始数据的字符串长度。那么我们再来看执行的命令:

/usr/local/mysql/bin/mysqldumpslow -s at -t 15 /root/db01-102-slow.log 有 -t 15这一句,那么就是要显示出前15个记录,那么如果我的slow.log统计出来只有12个不到15个,而这里有继续遍历到15的话,那进程肯定会Died。


所以这里有2个解决方案:

1 修改/usr/local/mysql/bin/mysqldumpslow里面的源代码,加null判断。

这个过程有些复杂,暂时略过吧,期待后续空了再研究。


2 修改命令/usr/local/mysql/bin/mysqldumpslow -s at -t 15 /root/db01-102-slow.log ,把-t 15修改成-t 10或者-t 5试试。

试了好几次,发现临界点在-t 7上面,如下:

[root@slave~]# /usr/local/mysql/bin/mysqldumpslow -s at -t 8 /root/db01-102-slow.log 
Reading mysql slow query log from /root/db01-102-slow.log
Count: 22  Time=13.20s (290s)  Lock=0.00s (0s)  Rows=10.0 (220), [dubbo]@2hosts
  select 
  coupon_id, coupon_lot.coupon_lot_id, coupon_lot.remark,
  coupon.code,  coupon_lot.coupon_type, coupon.state,
  coupon_lot.ckey, coupon_lot.cvalue, coupon_lot.discount, coupon_lot.type, coupon_lot.channel, 
  coupon_lot.is_reusable, coupon_lot.start_datetime,
  coupon_lot.end_datetime, coupon_lot.create_datetime, coupon.update_datetime ,coupon_lot.department,
  coupon_lot.state as couponLotState, coupon_lot.create_operator,coupon_lot.coupon_category,
  coupon_lot.pdt_code,brand.brand_name,product_category.category_name
  from coupon_lot
  left join coupon 
  on coupon.coupon_lot_id = coupon_lot.coupon_lot_id
  LEFT JOIN brand
  ON brand.brand_id=coupon_lot.brand_id
  LEFT JOIN product_category
  on product_category.category_id=coupon_lot.category_id
  group by coupon_lot.coupon_lot_id
  order by coupon_lot.create_datetime DESC
  limit N,N

Count: 22  Time=9.61s (211s)  Lock=0.00s (0s)  Rows=1.0 (22), [dubbo]@2hosts
  select count(*)
  from coupon_lot
  left join coupon 
  on coupon.coupon_lot_id = coupon_lot.coupon_lot_id
  LEFT JOIN brand
  ON brand.brand_id=coupon_lot.brand_id
  LEFT JOIN product_category
  on product_category.category_id=coupon_lot.category_id

Count: 5  Time=2.47s (12s)  Lock=0.00s (0s)  Rows=0.0 (0), [dubbo]@2hosts
  select
  user_id, usename, nickname, password, user_group_id, realname, gender, email, mobilephone, 
  birthday, province_id, city_id, district_id, marry, income, remarks, create_datetime, 
  active_state, verityEmail, verityPhone, credit, last_login, last_ip, is_locked, channel, 
  tag, union_partner_uuid, union_user_safekey, is_black, qq, weibo_id, verity_email_key, 
  verity_phone_key, verity_email_datetime, verity_phone_datetime, verity_question, 
  verity_answer, cps_code, cps_time_from, cps_time_to, cps_cookie, first_channel
  from user_info where mobilephone = 'S' and (channel is null or trim(channel) ='S')

Count: 177  Time=1.40s (247s)  Lock=0.00s (0s)  Rows=1.0 (177), [xx]@2hosts
  select count(*) from user_info
  LEFT JOIN system_region a
  ON province_id =a.region_id
  LEFT JOIN system_region b
  ON city_id = b.region_id
  LEFT JOIN system_region c
  ON district_id = c.region_id

Count: 1  Time=1.13s (1s)  Lock=0.00s (0s)  Rows=10.0 (10), [xx]@[xxx]
  select 
  return_sn,  relating_order_sn, return_from,  oi.order_out_sn ,
  add_time , return_type, 
  return_pay, ui.usename as userName, return_consignee, return_goods_count ,
  return_total_fee, total_paid, 
  return_desc, return_order_status,  return_pay_status ,
  return_shipping_status, order_return.lock_operator, order_return.return_invoice_no
  from order_return  LEFT JOIN   order_info oi
  on order_return.relating_order_sn = oi.order_sn 
  left join user_info ui on oi.user_id = ui.user_id
  left join order_payment on order_payment.order_sn = oi.order_sn
  order by order_return.add_time DESC
  , oi.order_sn 
  limit N,N

Count: 8  Time=1.09s (8s)  Lock=0.00s (0s)  Rows=10.0 (80), [xx]@2hosts
  select 
  return_sn,  relating_order_sn, return_from,  oi.order_out_sn ,
  add_time , return_type, 
  return_pay, ui.usename as userName, return_consignee, return_goods_count ,
  return_total_fee, total_paid, 
  return_desc, return_order_status,  return_pay_status ,
  return_shipping_status, order_return.lock_operator, order_return.return_invoice_no
  from order_return  LEFT JOIN   order_info oi
  on order_return.relating_order_sn = oi.order_sn 
  left join user_info ui on oi.user_id = ui.user_id
  left join order_payment on order_payment.order_sn = oi.order_sn
  order by order_return.add_time DESC
  limit N,N

Count: 1  Time=1.00s (1s)  Lock=0.00s (0s)  Rows=1.0 (1), root[root]@localhost
  select sleep(N)

Died at /usr/local/mysql/bin/mysqldumpslow line 161, <> chunk 236.

-- 临界点 -t 7
[root@db-master-2 ~]# /usr/local/mysql/bin/mysqldumpslow -s at -t 7 /root/db01-102-slow.log 

Reading mysql slow query log from /root/db01-102-slow.log
Count: 22  Time=13.20s (290s)  Lock=0.00s (0s)  Rows=10.0 (220), [xx]@2hosts
  select 
  coupon_id, coupon_lot.coupon_lot_id, coupon_lot.remark,
  coupon.code,  coupon_lot.coupon_type, coupon.state,
  coupon_lot.ckey, coupon_lot.cvalue, coupon_lot.discount, coupon_lot.type, coupon_lot.channel, 
  coupon_lot.is_reusable, coupon_lot.start_datetime,
  coupon_lot.end_datetime, coupon_lot.create_datetime, coupon.update_datetime ,coupon_lot.department,
  coupon_lot.state as couponLotState, coupon_lot.create_operator,coupon_lot.coupon_category,
  coupon_lot.pdt_code,brand.brand_name,product_category.category_name
  from coupon_lot
  left join coupon 
  on coupon.coupon_lot_id = coupon_lot.coupon_lot_id
  LEFT JOIN brand
  ON brand.brand_id=coupon_lot.brand_id
  LEFT JOIN product_category
  on product_category.category_id=coupon_lot.category_id
  group by coupon_lot.coupon_lot_id
  order by coupon_lot.create_datetime DESC
  limit N,N

Count: 22  Time=9.61s (211s)  Lock=0.00s (0s)  Rows=1.0 (22), [dubbo]@2hosts
  select count(*)
  from coupon_lot
  left join coupon 
  on coupon.coupon_lot_id = coupon_lot.coupon_lot_id
  LEFT JOIN brand
  ON brand.brand_id=coupon_lot.brand_id
  LEFT JOIN product_category
  on product_category.category_id=coupon_lot.category_id

Count: 5  Time=2.47s (12s)  Lock=0.00s (0s)  Rows=0.0 (0), [xx]@2hosts
  select
  user_id, usename, nickname, password, user_group_id, realname, gender, email, mobilephone, 
  birthday, province_id, city_id, district_id, marry, income, remarks, create_datetime, 
  active_state, verityEmail, verityPhone, credit, last_login, last_ip, is_locked, channel, 
  tag, union_partner_uuid, union_user_safekey, is_black, qq, weibo_id, verity_email_key, 
  verity_phone_key, verity_email_datetime, verity_phone_datetime, verity_question, 
  verity_answer, cps_code, cps_time_from, cps_time_to, cps_cookie, first_channel
  from user_info where mobilephone = 'S' and (channel is null or trim(channel) ='S')

Count: 177  Time=1.40s (247s)  Lock=0.00s (0s)  Rows=1.0 (177), [xx]@2hosts
  select count(*) from user_info
  LEFT JOIN system_region a
  ON province_id =a.region_id
  LEFT JOIN system_region b
  ON city_id = b.region_id
  LEFT JOIN system_region c
  ON district_id = c.region_id

Count: 1  Time=1.13s (1s)  Lock=0.00s (0s)  Rows=10.0 (10), [dubbo]@[xxx]
  select 
  return_sn,  relating_order_sn, return_from,  oi.order_out_sn ,
  add_time , return_type, 
  return_pay, ui.usename as userName, return_consignee, return_goods_count ,
  return_total_fee, total_paid, 
  return_desc, return_order_status,  return_pay_status ,
  return_shipping_status, order_return.lock_operator, order_return.return_invoice_no
  from order_return  LEFT JOIN   order_info oi
  on order_return.relating_order_sn = oi.order_sn 
  left join user_info ui on oi.user_id = ui.user_id
  left join order_payment on order_payment.order_sn = oi.order_sn
  order by order_return.add_time DESC
  , oi.order_sn 
  limit N,N

Count: 8  Time=1.09s (8s)  Lock=0.00s (0s)  Rows=10.0 (80), [dubbo]@2hosts
  select 
  return_sn,  relating_order_sn, return_from,  oi.order_out_sn ,
  add_time , return_type, 
  return_pay, ui.usename as userName, return_consignee, return_goods_count ,
  return_total_fee, total_paid, 
  return_desc, return_order_status,  return_pay_status ,
  return_shipping_status, order_return.lock_operator, order_return.return_invoice_no
  from order_return  LEFT JOIN   order_info oi
  on order_return.relating_order_sn = oi.order_sn 
  left join user_info ui on oi.user_id = ui.user_id
  left join order_payment on order_payment.order_sn = oi.order_sn
  order by order_return.add_time DESC
  limit N,N

Count: 1  Time=1.00s (1s)  Lock=0.00s (0s)  Rows=1.0 (1), root[root]@localhost
  select sleep(N)

[root@db-master-2 ~]# 

最终总结:
mysqldumpslow报错:Died at /usr/local/mysql/bin/mysqldumpslow line 161, <> chunk 236.是因为top数目太多了,mysqldumpslow遍历不过来的缘故。

[root@node3 bin]# ls ibd2sdi my_print_defaults mysqld mysql_migrate_keyring mysql_upgrade innochecksum mysql mysqld-debug mysqlpump perror lz4_decompress mysqladmin mysqld_multi mysql_secure_installation zlib_decompress myisamchk mysqlbinlog mysqld_safe mysqlshow myisam_ftdump mysqlcheck mysqldump mysqlslap myisamlog mysql_config mysqldumpslow mysql_ssl_rsa_setup myisampack mysql_config_editor mysqlimport mysql_tzinfo_to_sql [root@node3 bin]# ./mysqld --initialize --console --lower-case-table-names=1 ./mysqld: /lib64/libstdc++.so.6: version `CXXABI_1.3.11' not found (required by ./mysqld) ./mysqld: /lib64/libstdc++.so.6: version `CXXABI_1.3.8' not found (required by ./mysqld) ./mysqld: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.22' not found (required by ./mysqld) ./mysqld: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by ./mysqld) ./mysqld: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by ./mysqld) ./mysqld: /lib64/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by ./mysqld) ./mysqld: /lib64/libm.so.6: version `GLIBC_2.27' not found (required by ./mysqld) ./mysqld: /lib64/libc.so.6: version `GLIBC_2.28' not found (required by ./mysqld) ./mysqld: /lib64/libc.so.6: version `GLIBC_2.25' not found (required by /usr/local/mysql-8.1.0/bin/../lib/private/libcrypto.so.3) ./mysqld: /lib64/libc.so.6: version `GLIBC_2.28' not found (required by /usr/local/mysql-8.1.0/bin/../lib/private/libprotobuf-lite.so.3.19.4) ./mysqld: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by /usr/local/mysql-8.1.0/bin/../lib/private/libprotobuf-lite.so.3.19.4) ./mysqld: /lib64/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by /usr/local/mysql-8.1.0/bin/../lib/private/libprotobuf-lite.so.3.19.4) ./mysqld: /lib64/libstdc++.so.6: version `CXXABI_1.3.8' not found (required by /usr/local/mysql-8.1.0/bin/../lib/private/libprotobuf-lite.so.3.19.4) ./mysqld: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by /usr/local/mysql-8.1.0/bin/../lib/private/libprotobuf-lite.so.3.19.4)
最新发布
08-28
<think>我们遇到了一个典型的动态库依赖问题,具体是运行mysqld初始化时缺少所需的GLIBC和CXXABI版本。这通常是因为系统自带的库版本过低,而MySQL 8.1要求更高版本的库。 ### 错误分析 错误信息显示需要以下库版本: - `GLIBC_2.25`, `GLIBC_2.27`, `GLIBC_2.28` - `GLIBCXX_3.4.20` 到 `3.4.22` - `CXXABI_1.3.8`, `CXXABI_1.3.9`, `CXXABI_1.3.11` ### 解决方案 #### 方法1:升级系统GLIBC(不推荐) 直接升级GLIBC风险极高,可能导致系统崩溃。 #### 方法2:使用兼容的MySQL版本(推荐) 安装与当前系统兼容的MySQL版本: ```bash # 查看当前系统GLIBC版本 ldd --version | head -n1 # 如果系统较旧(如CentOS 7),应安装MySQL 5.7或使用官方Yum源 sudo yum install https://dev.mysql.com/get/mysql80-community-release-el7-7.noarch.rpm sudo yum install mysql-community-server ``` #### 方法3:静态编译版本(最佳实践) 下载MySQL的静态编译版本(包含所有依赖): 1. 访问 [MySQL下载页面](https://dev.mysql.com/downloads/mysql/) 2. 选择 **Linux - Generic** 版本 3. 下载包含 **bundle** 或 **all libraries** 的包 #### 方法4:手动编译高版本库(复杂) 在非系统目录编译高版本库并指定路径: ```bash # 编译GLIBC(需极高谨慎) wget https://ftp.gnu.org/gnu/glibc/glibc-2.28.tar.gz tar xf glibc-2.28.tar.gz cd glibc-2.28 mkdir build && cd build ../configure --prefix=/opt/glibc-2.28 make -j4 && sudo make install # 设置环境变量 export LD_LIBRARY_PATH=/opt/glibc-2.28/lib:$LD_LIBRARY_PATH ``` ### 临时验证方法 ```bash # 尝试使用LD_LIBRARY_PATH指向MySQL自带的库(如果存在) ./mysqld --initialize --console --ld-library-path=./lib ``` ### 系统兼容性建议表 | 系统版本 | 最高支持MySQL版本 | 解决方案 | |----------------|-------------------|------------------------| | CentOS/RHEL 6 | MySQL 5.6 | 升级系统或使用Docker | | CentOS/RHEL 7 | MySQL 8.0.28 | 使用官方Yum源 | | Ubuntu 16.04 | MySQL 8.0.31 | 使用APT源安装 | > **警告**:切勿在生产环境强制修改GLIBC,可能导致SSH等基础服务崩溃! ### 安回退方案 使用Docker容器化部署: ```bash docker run --name mysql8 \ -e MYSQL_ROOT_PASSWORD=your_pass \ -e MYSQL_LOWER_CASE_TABLE_NAMES=1 \ -d mysql:8.0 \ --lower-case-table-names=1 ``` §§相关问题§§ 1. 如何在不升级系统的情况下,安地检测并修复Linux服务器上的GLIBC版本不兼容问题? 2.使用Docker部署MySQL时,如何确保数据目录的持久化存储以及性能优化? 3. 对于已存在的低版本MySQL实例(如5.6),升级到8.0版本需要遵循哪些关键步骤以避免库依赖问题? 4. 在编译安装高版本GLIBC时,如何避免破坏系统原有依赖导致关键服务崩溃? 5. 如何通过配置Yum源或APT源确保自动安装与当前系统兼容的MySQL版本?</think>### MySQL初始化失败:GLIBC和CXXABI版本缺失解决方案 #### 错误原因分析 您遇到的错误是由于系统缺少MySQL 8.1所需的底层库依赖: 1. **GLIBC版本过低**: - 需要:GLIBC_2.25/2.27/2.28 - 当前:CentOS/RHEL 7默认最高GLIBC_2.17 2. **C++ ABI不兼容**: - 需要:CXXABI_1.3.8/1.3.9/1.3.11 - 当前:系统libstdc++.so.6版本过低 3. **根本原因**: - MySQL 8.1编译环境比您的操作系统(CentOS/RHEL 7)更新 #### 三种解决方案 ##### ✅ 方案1:安装兼容版本(推荐) ```bash # 删除当前MySQL 8.1 rm -rf /usr/local/mysql-8.1.0 # 下载CentOS 7兼容的MySQL 8.0 wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.36-linux-glibc2.17-x86_64.tar.xz # 解压并安装 tar xvf mysql-8.0.36-linux-glibc2.17-x86_64.tar.xz mv mysql-8.0.36-linux-glibc2.17-x86_64 /usr/local/mysql cd /usr/local/mysql/bin # 重新初始化(使用兼容版本) ./mysqld --initialize --console --lower-case-table-names=1 ``` ##### ⚠️ 方案2:升级系统库(有风险) ```bash # 安装devtoolset-9(提供较新GLIBC) sudo yum install centos-release-scl sudo yum install devtoolset-9 # 启用新工具链 scl enable devtoolset-9 bash # 验证GLIBC版本 strings /lib64/libc.so.6 | grep GLIBC # 尝试重新运行初始化 ./mysqld --initialize --console --lower-case-table-names=1 ``` ##### 🐳 方案3:使用Docker容器(最安) ```bash # 创建数据目录 mkdir -p /mysql/data && chmod 777 /mysql/data # 启动MySQL 8.1容器 docker run -d --name mysql8 \ -v /mysql/data:/var/lib/mysql \ -e MYSQL_ROOT_PASSWORD=your_password \ -e MYSQL_LOWER_CASE_TABLE_NAMES=1 \ mysql:8.1 \ --lower-case-table-names=1 ``` #### 预防措施 1. **版本兼容性检查**: ```bash # 检查GLIBC支持 strings /lib64/libc.so.6 | grep GLIBC # 检查CXXABI支持 strings /lib64/libstdc++.so.6 | grep CXXABI ``` 2. **MySQL版本选择指南**: | 操作系统 | 推荐MySQL版本 | 备注 | |--------------|---------------|--------------------------| | CentOS/RHEL 6| 5.7 | 官方支持的最高版本 | | CentOS/RHEL 7| 8.0.36 | 使用glibc2.17编译的版本 | | CentOS/RHEL 8| 8.1+ | 完兼容 | 3. **安装前验证脚本**: ```bash #!/bin/bash REQUIRED_GLIBC="2.25" CURRENT_GLIBC=$(ldd --version | head -1 | awk '{print $NF}') if [ "$(printf '%s\n' "$REQUIRED_GLIBC" "$CURRENT_GLIBC" | sort -V | head -n1)" != "$REQUIRED_GLIBC" ]; then echo "错误:需要GLIBC $REQUIRED_GLIBC+, 当前为 $CURRENT_GLIBC" exit 1 fi ``` > **重要提示**:生产环境切勿强制升级GLIBC,可能导致系统崩溃!
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值