The newly created data directory /usr/local/mysql/data/ by --initialize is unusable. You can remove

昨天晚上打算把自己源码编译的mysql8docker镜像搭建一下主从复制。我使用本地目录挂载到了mysql容器的data目录。然后使用/usr/local/mysql/bin/mysqld --initialize-insecure --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data user=mysql 命令初始化了目录。my.cnf配置如下:

[client]
default-character-set=utf8
#password = your_password
port = 3306
socket = /tmp/mysql.sock


[mysqld]
#sql_mode=STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION
character-set-server=utf8mb4
port = 3306
socket = /tmp/mysql.sock
basedir = /usr/local/mysql/
datadir = /usr/local/mysql/data/

skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
init_connect='SET NAMES utf8'

# 错误日志配置
log-error = /usr/local/mysql/log/error.log
pid-file = /usr/local/mysql/run/mysql.pid

#慢日志设置
slow_query_log=1
long_query_time=2
slow_query_log_file=/usr/local/mysql/log/slow_query.log

# bin-log二进制日志设置
log-bin=/usr/local/mysql/log/mysqlbin/mysql-bin
# logging format: mixed|statement|row
binlog_format=statement


# 主从配置
# required unique id between 1 and 2^32 - 1 defaults to 1 if master-host is not set
server-id = 1

#Innodb配置
innodb_data_home_dir = /usr/local/mysql/data
#innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /usr/local/mysql/data
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
innodb_buffer_pool_size = 128M
innodb_additional_mem_pool_size = 10M
# Set .._log_file_size to 25 % of buffer pool size
innodb_log_file_size = 32M
innodb_log_buffer_size = 10M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 10


[myisamchk]
key_buffer_size = 128M
sort_buffer_size = 128M
read_buffer = 2M
write_buffer = 2M

令我意外的是mysql初始化失败了报错内容如下:

2020-06-26T15:58:05.081668Z 0 [ERROR] [MY-013455] [Server] The newly created data directory /usr/local/mysql/data/ by --initialize is unusable. You can remove it.
2020-06-26T15:58:05.082758Z 0 [ERROR] [MY-010119] [Server] Aborting

意思是初始化mysql的data数据目录不可用。

在经过了一番折腾之后还是不行,google、百度很久都没有找到解决办法,无奈只能自己找问题。

既然是报错的是data目录不可用,那好,我就从这里入手,由于docker挂载目录是不允许删除的,我就run了一个测试容器(无挂载目录,无配置),然后在容器中执行初始化命令。结果初始化成功了。此时已经距离成功不远。

我基本断行是关于data目录配置的关系了。想想自己设置开启主从配置,也就修改了几个配置项而已。有关data数据目录也就只有bin-log的存储位置了,如下图所示:
The newly created data directory /usr/local/mysql/data/ by --initialize is unusable. You can remove_第1张图片
然后我尝试将这个配置项注释(mysql8默认是开启bin-log的),然后重新初始化mysql,果然是这个配置的问题。初始化成功了。

问题是解决了,可是为什么修改了bin-log目录会失败呢?打开官方文档,找到关于–bin-log的配置。原文如下
The newly created data directory /usr/local/mysql/data/ by --initialize is unusable. You can remove_第2张图片
只能在初始化的时候使用–bin-log 指定目录

总结:如果有自定义my.cnf配置bin-log 目录及文件的6一定要在初始化的时候指定目录/usr/local/mysql/bin/mysqld --log-bin=[自定义的二进制目录]
另外需要注意的是,自定义的目录必须先创建好,mysql初始化不会自动创建自定义的binlog目录

/usr/local/mysql/bin/mysqld --initialize-insecure --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --log-bin=/usr/local/mysql/log/mysqlbin/mysql-bin --user=mysql

你可能感兴趣的:(mysql,环境安装,mysql初始化data,mysql)