mysql入坑之路(7) 初始化mysql数据库,datadir目录需要未空
参考文档:
https://www.cnblogs.com/baixing/articles/14771099.html
查看datadir目录配置:
[root@localhost mysql]# cat my.cnf
[mysqld]
datadir = /var/lib/mysql
初始化数据库
始化mysql。
进入mysql程序目录下有个mysql_install_db可执行文件。运行
/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data &(这点非常重要)
报错输出
# mysql_install_db 已弃用--输出
[root@localhost mysql]# /home/demo-8888/mysql5.7-37/bin/mysql_install_db --user=mysql --basedir=/home/demo-8888/mysql5.7-37 --datadir=/home/demo-8888/mysql6-data
2022-09-15 11:07:41 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2022-09-15 11:07:41 [ERROR] The data directory '/home/demo-8888/mysql6-data' already exist and is not empty.
------------翻译:
2022-09-15 11:07:41 [警告] mysql_install_db 已弃用。 请考虑切换到 mysqld --initialize
2022-09-15 11:07:41 [错误] 数据目录 '/home/demo-8888/mysql6' 已存在且不为空。
# mysqld --initialize --输出
[root@localhost mysql]# /home/demo-8888/mysql5.7-37/bin/mysqld --user=mysql --basedir=/home/demo-8888/mysql5.7-37 --datadir=/home/demo-8888/mysql6-data --initialize
2022-09-15T03:08:31.411273Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-09-15T03:08:31.412201Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
2022-09-15T03:08:31.412224Z 0 [ERROR] Aborting
------------翻译:
2022-09-15T03:08:31.411273Z 0 [警告] 带有隐式 DEFAULT 值的 TIMESTAMP 已弃用。 请使用 --explicit_defaults_for_timestamp 服务器选项(有关详细信息,请参阅文档)。
2022-09-15T03:08:31.412201Z 0 [错误] -- 指定初始化,但数据目录中有文件。 中止。
2022-09-15T03:08:31.412224Z 0 [错误] 中止
解决方案:
清空 datadir=/home/demo-8888/mysql6-data 目录,重新初始化