安装mysql 5.7.16
在需要执行mysqld --initialize --user=mysql
命令对mysql数据库初始化的情况下包了两个错误
报错一 --initialize specified but the data directory has files in it. Aborting.
[root@lzs mysql5.7]# mysqld --initialize --user=mysql
2020-05-26T12:11:14.759497Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-05-26T12:11:14.761046Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
2020-05-26T12:11:14.761084Z 0 [ERROR] Aborting
my.cnf文件添加配置
注意添加前一定要给my.cnf这个文件备份,
explicit_defaults_for_timestamp=1
即使复制粘贴拷贝了配置,也可能死活起不起来
不知道为啥,第一次替换修改保存后,服务怎么启动不起来,然后我重新覆盖了一份备份的my.cnf
再修改一次成功
报错二 [ERROR] --initialize specified but the data directory has files in it. Aborting.
在进行mysqld --initialize --user=mysql
初始化的时候报错2
解决
更改后
vim /etc/my.cnf
查看文件,寻找datadir=...
查看到:datadir=/usr/local/mysql/data,
这个是data保存目录。
进入/usr/local/mysql/data后,查看到确实有数据:
将/usr/local/mysql/data备份,
cd /usr/local/mysql
mv data data.bak
接着执行:
# mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data# systemctl start mysqld