MySQL修改innodb_data_file_path参数的一些注意事项
前言
innodb_data_file_path用来指定innodb tablespace文件,如果我们不在my.cnf文件中指定innodb_data_home_dir和innodb_data_file_path那么默认会在datadir目录下创建ibdata1 作为innodb tablespace。
说明
在测试环境下没有设置过多的详细参数就初始化并启动了服务,后期优化的过程中发现innodb_data_file_path设置过小:
root@node1 14:59: [(none)]> show variables like '%innodb_data_file_path%'; +-----------------------+------------------------+ | variable_name | value | +-----------------------+------------------------+ | innodb_data_file_path | ibdata1:12m:autoextend | +-----------------------+------------------------+ 1 row in set (0.00 sec) root@node1 14:59: [(none)]>
当没有配置innodb_data_file_path时,默认innodb_data_file_path = ibdata1:12m:autoextend
[mysqld] innodb_data_file_path = ibdata1:12m:autoextend
当需要改为1g时,不能直接在配置文件把 ibdata1 改为 1g ,
[mysqld] innodb_data_file_path = ibdata1:1g:autoextend
否则启动服务之后,从错误日志看到如下报错:
2019-03-29t06:47:32.044316z 0 [error] innodb: the auto-extending innodb_system data file './ibdata1' is of a different size 768 pages (rounded down to mb) than specified in the .cnf file: initial 65536 pages, max 0 (relevant if non-zero) pages!
大致意思就是ibdata1的大小不是 65536page*16kb/1024kb=1g
,而是 786page*16kb/1024kb=12m
(未使用压缩页)
方法一:推荐
而应该再添加一个 ibdata2:1g ,如下:
[mysqld] innodb_data_file_path = ibdata1:12m;ibdata2:1g:autoextend
重启数据库!
方法二:不推荐
直接改为如下的话
[mysqld] innodb_data_file_path = ibdata1:1g:autoextend
可以删除$mysql_datadir目录下 ibdata1、ib_logfile0、ib_logfile1 文件:
rm -f ibdata* ib_logfile*
也可以启动mysql,但是mysql错误日志里会报如下错误:
2019-03-29t07:10:47.844560z 0 [warning] could not increase number of max_open_files to more than 5000 (request: 65535) 2019-03-29t07:10:47.844686z 0 [warning] changed limits: table_open_cache: 1983 (requested 2000) 2019-03-29t07:10:48.028262z 0 [warning] 'no_auto_create_user' sql mode was not set. 2019-03-29t07:10:48.147653z 0 [warning] innodb: cannot open table mysql/plugin from the internal data dictionary of innodb though the .frm file for the table exists. please refer to http://dev.mysql.com/doc/refman/5.7/en/innodb-troubleshooting.html for how to resolve the issue. mysqld: table 'mysql.plugin' doesn't exist 2019-03-29t07:10:48.147775z 0 [error] can't open the mysql.plugin table. please run mysql_upgrade to create it. 2019-03-29t07:10:48.163444z 0 [warning] innodb: cannot open table mysql/gtid_executed from the internal data dictionary of innodb though the .frm file for the table exists. please refer to http://dev.mysql.com/doc/refman/5.7/en/innodb-troubleshooting.html for how to resolve the issue. mysqld: table 'mysql.gtid_executed' doesn't exist 2019-03-29t07:10:48.163502z 0 [warning] gtid table is not ready to be used. table 'mysql.gtid_executed' cannot be opened. 2019-03-29t07:10:48.163658z 0 [warning] innodb: cannot open table mysql/gtid_executed from the internal data dictionary of innodb though the .frm file for the table exists. please refer to http://dev.mysql.com/doc/refman/5.7/en/innodb-troubleshooting.html for how to resolve the issue. mysqld: table 'mysql.gtid_executed' doesn't exist 2019-03-29t07:10:48.163711z 0 [warning] gtid table is not ready to be used. table 'mysql.gtid_executed' cannot be opened. 2019-03-29t07:10:48.164619z 0 [warning] failed to set up ssl because of the following ssl library error: ssl context is not usable without certificate and private key 2019-03-29t07:10:48.166805z 0 [warning] innodb: cannot open table mysql/server_cost from the internal data dictionary of innodb though the .frm file for the table exists. please refer to http://dev.mysql.com/doc/refman/5.7/en/innodb-troubleshooting.html for how to resolve the issue. 2019-03-29t07:10:48.166891z 0 [warning] failed to open optimizer cost constant tables 2019-03-29t07:10:48.168072z 0 [warning] innodb: cannot open table mysql/time_zone_leap_second from the internal data dictionary of innodb though the .frm file for the table exists. please refer to http://dev.mysql.com/doc/refman/5.7/en/innodb-troubleshooting.html for how to resolve the issue. 2019-03-29t07:10:48.168165z 0 [warning] can't open and lock time zone table: table 'mysql.time_zone_leap_second' doesn't exist trying to live without them 2019-03-29t07:10:48.169454z 0 [warning] innodb: cannot open table mysql/servers from the internal data dictionary of innodb though the .frm file for the table exists. please refer to http://dev.mysql.com/doc/refman/5.7/en/innodb-troubleshooting.html for how to resolve the issue. 2019-03-29t07:10:48.169527z 0 [error] can't open and lock privilege tables: table 'mysql.servers' doesn't exist 2019-03-29t07:10:48.170042z 0 [warning] innodb: cannot open table mysql/slave_master_info from the internal data dictionary of innodb though the .frm file for the table exists. please refer to http://dev.mysql.com/doc/refman/5.7/en/innodb-troubleshooting.html for how to resolve the issue. 2019-03-29t07:10:48.170617z 0 [warning] innodb: cannot open table mysql/slave_relay_log_info from the internal data dictionary of innodb though the .frm file for the table exists. please refer to http://dev.mysql.com/doc/refman/5.7/en/innodb-troubleshooting.html for how to resolve the issue. 2019-03-29t07:10:48.170946z 0 [warning] innodb: cannot open table mysql/slave_master_info from the internal data dictionary of innodb though the .frm file for the table exists. please refer to http://dev.mysql.com/doc/refman/5.7/en/innodb-troubleshooting.html for how to resolve the issue. 2019-03-29t07:10:48.171046z 0 [warning] info table is not ready to be used. table 'mysql.slave_master_info' cannot be opened. 2019-03-29t07:10:48.171272z 0 [warning] innodb: cannot open table mysql/slave_worker_info from the internal data dictionary of innodb though the .frm file for the table exists. please refer to http://dev.mysql.com/doc/refman/5.7/en/innodb-troubleshooting.html for how to resolve the issue. 2019-03-29t07:10:48.171626z 0 [warning] innodb: cannot open table mysql/slave_relay_log_info from the internal data dictionary of innodb though the .frm file for the table exists. please refer to http://dev.mysql.com/doc/refman/5.7/en/innodb-troubleshooting.html for how to resolve the issue. 2019-03-29t07:10:48.171688z 0 [warning] info table is not ready to be used. table 'mysql.slave_relay_log_info' cannot be opened.
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对的支持。