1. 安装mysql,就不说了。
2. 将数据目录修改到home下:
修改/etc/my.cnf,将datadir=/var/lib/mysql改为 datadir=/home/mysql/data
这时启动mysqld就应该可以了,但我启动时报错:
bash-5.1$ sudo systemctl start mysqld
Job for mysqld.service failed because the control process exited with error code.
See "systemctl status mysqld.service" and "journalctl -xeu mysqld.service" for details.
看/var/log/mysqld.log:
2025-02-18T11:56:53.718686Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.41) initializing of server in progress as process 16685
2025-02-18T11:56:53.720480Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
2025-02-18T11:56:53.720509Z 0 [ERROR] [MY-013236] [Server] The designated data directory /home/mysql/data/ is unusable. You can remove all files
that the server added to it.
2025-02-18T11:56:53.720564Z 0 [ERROR] [MY-010119] [Server] Aborting
2025-02-18T11:56:53.720678Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.41) MySQL Community Server - GPL.
2025-02-18T11:56:53.954261Z 0 [Warning] [MY-010091] [Server] Can't create test file /home/mysql/data/mysqld_tmp_file_case_insensitive_test.lower
-test
2025-02-18T11:56:53.954342Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.41) starting as process 16687
2025-02-18T11:56:53.956470Z 0 [Warning] [MY-010091] [Server] Can't create test file /home/mysql/data/mysqld_tmp_file_case_insensitive_test.lower
-test
2025-02-18T11:56:53.956478Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /home/mysql/data/ is case
insensitive
mysqld: File './binlog.index' not found (OS errno 13 - Permission denied)
2025-02-18T11:56:53.957108Z 0 [ERROR] [MY-010119] [Server] Aborting
2025-02-18T11:56:53.957220Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.41) MySQL Community Server - GPL.
总之报错内容就是数据路径的权限问题,但无论我怎么修改/home/mysql/data目录的权限都无济于事,总是报这个错。
后来检查selinux发现没有关闭,果断关闭selinux:
vi /etc/selinux/config:
SELINUX=disabled
修改后重启系统。问题解决!