无法启动 MySQL 服务器。无法将 datadir 设置为“/var/lib/mysql/”

无法启动 MySQL 服务器。无法将 datadir 设置为“/var/lib/mysql/”

我在新安装的 Xubuntu 22.04 上从 MySQL APT 存储库安装了 MySQL 8.0.31-1 Ubuntu 22.04。我无法启动 MySQL 服务器。我收到以下警告和错误:

[Warning] [MY-010091] [Server] Can't create test file /var/lib/mysql/mysqld_tmp_file_case_insensitive_test.lower-test
[System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.31) starting as process 2169
[Warning] [MY-010091] [Server] Can't create test file /var/lib/mysql/mysqld_tmp_file_case_insensitive_test.lower-test
[Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /var/lib/mysql/ is case insensitive
[ERROR] [MY-013276] [Server] Failed to set datadir to '/var/lib/mysql/' (OS errno: 13 - Permission denied)
[ERROR] [MY-010119] [Server] Aborting
[System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.31)  MySQL Community Server - GPL.

权限/var/lib/mysql/drwx------ 7 mysql mysql

我尝试将 datadir 设置为/usr/local/mysql。我以为我已将权限设置为与上面相同的权限。当我mysqld --initialize --user=mysql尝试将其初始化为数据目录时,我得到了以下结果:

[System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.31) initializing of server in progress as process 5588
[ERROR] [MY-013236] [Server] The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it.
[ERROR] [MY-010119] [Server] Aborting
[System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.31)  MySQL Community Server - GPL.

我是否遇到了权限问题?另外,如果 datadir 应该是/var/lib/mysql/,那么应该在哪里设置?应该在 中设置吗/etc/mysql/conf.d/mysql.cnf?我在 Windows 10 下运行过 MySQL,也使用过 Linux。但是,这是我第一次尝试将两者结合使用。

更新:我确实找到了datadir = /var/lib/mysql,它位于/etc/mysql/mysql.conf.d/mysqld.cnf。所以看起来是对的。但我仍然不确定问题出在哪里。

解决:我一直没能找到问题所在。由于我的系统尚未 100% 配置完成,我只能擦除驱动器,安装一个新系统,然后安装 MariaDB。我可能一开始就应该这么做。

相关内容