关于innodb_data_file_path设置
启动Mysql时报错,无法正常启动,通过日志发有数据文件大小错误,日志如下截图:
[ERROR] InnoDB: auto-extending data file /usr/local/mysql/data/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!
2018-05-25 14:27:04 6002 [ERROR] InnoDB: Could not open or create the system tablespace. If you tried to add new data files to the system tablespace, and it failed here, you should now edit innodb_data_file_path in my.cnf back to what it was, and remove the new ibdata files InnoDB created in this failed attempt. InnoDB only wrote those files full of zeros, but did not yet use them in any way. But be careful: do not remove old data files which contain your precious data!说明:
innodb_data_file_path用来指定innodb tablespace文件,如果我们不在My.cnf文件中指定innodb_data_home_dir和innodb_data_file_path那么默认会在datadir目录下创建ibdata1 作为innodb tablespace。5.6.6之后 两个参数的默认值如下:show variables like 'innodb_data%';
+-----------------------+------------------------+
| Variable_name | Value |
+-----------------------+------------------------+
| innodb_data_file_path | ibdata1:12M:autoextend |
| innodb_data_home_dir | | >>note:虽然不指定innodb_data_home_dir和指定它为空显示是一样的,但是作用确不一样,如果不指定那么所有的innodb tablespace 文件只能存放在datadir目录下。如果显示指定为空,则可以为innodb tablespace 文件指定不同的路径
note:如果想为innodb tablespace指定不同目录下的文件,必须指定innodb_data_home_dir =。这个例子中会在datadir下建立ibdata1,在/data/mysql/mysql3306/data1/目录下创建ibdata2
如果我不指定innodb_data_home_dir =,只在my.cnf文件中做如下指定:
innodb_data_file_path = ibdata1:12M;/data/mysql/mysql3306/data1/ibdata2:12M:autoextend
然后使用该my.cnf文件进行数据库初始化的时候,会发现初始化失败,报错如下:
2016-03-24 16:58:34 29559 [ERROR] InnoDB: File .//data/mysql/mysql3306/data1/ibdata2: 'create' returned OS error 71. Cannot continue operation
##所以如果想为innodb tablespace文件指定不同路径,那么必须在my.cnf文件中指定innodb_data_home_dir =
参考资料:https://blog.csdn.net/shaochenshuo/article/details/50973068