gpt4 book ai didi

mysql - 在开发机器上移动 MySQL datadir

转载 作者:行者123 更新时间:2023-12-04 18:44:11 25 4
gpt4 key购买 nike

操作系统:Ubuntu 18.04
MySQL 版本:版本 8.0.19 for Linux on x86_64 (MySQL Community Server - GPL)

我的系统设置为使 Ubuntu 在 128gb SSD 上运行,并带有单独的 1TB SSD 用于存储。该系统采用 Windows 10 Pro 和 Ubuntu 18.04 进行双引导。存储驱动器为 NTFS 格式。

我想将 MySQL 数据目录移到存储驱动器上,因为我的操作系统驱动器不够大。
我一直在关注这个 URL 上的教程:https://www.digitalocean.com/community/tutorials/how-to-move-a-mysql-data-directory-to-a-new-location-on-ubuntu-16-04

我已经进入教程中的“第 4 步 - 重新启动 MySQL”。到目前为止,我已经将所有内容都跟踪到了 T,没有遗漏的逗号、正斜杠等。所有操作都完全按照描述进行(我已经多次检查以确保这是真的)

当我输入终端命令时

sudo systemctl start mysql

我得到以下输出
Job for mysql.service failed because the control process exited with error code.
See "systemctl status mysql.service" and "journalctl -xe" for details.

在此输出之后,我在终端中输入以下命令
systemctl status mysql.service

并收到以下输出
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Tue 2020-03-31 22:36:46 CDT; 38s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 7368 ExecStart=/usr/sbin/mysqld (code=exited, status=1/FAILURE)
Process: 7316 ExecStartPre=/usr/share/mysql-8.0/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
Main PID: 7368 (code=exited, status=1/FAILURE)
Status: "Server startup in progress"
Error: 13 (Permission denied)

Mar 31 22:36:46 user-desktop mysqld[7368]: 2020-04-01T03:36:46.436713Z 0 [Warning] [MY-010091] [Server] Can't create test file /media/user/storage/mysql_datadir/mysql/mysqld_tmp_file_case_insensitive_test.lower-test
Mar 31 22:36:46 user-desktop mysqld[7368]: 2020-04-01T03:36:46.436796Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.19) starting as process 7368
Mar 31 22:36:46 user-desktop mysqld[7368]: 2020-04-01T03:36:46.439912Z 0 [Warning] [MY-010091] [Server] Can't create test file /media/user/storage/mysql_datadir/mysql/mysqld_tmp_file_case_insensitive_test.lower-test
Mar 31 22:36:46 user-desktop mysqld[7368]: 2020-04-01T03:36:46.439923Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /media/user/storage/mysql_datadir/mysql/ is case insensitive
Mar 31 22:36:46 user-desktop mysqld[7368]: 2020-04-01T03:36:46.439961Z 0 [ERROR] [MY-013276] [Server] Failed to set datadir to '/media/user/storage/mysql_datadir/mysql/' (OS errno: 13 - Permission denied)
Mar 31 22:36:46 user-desktop mysqld[7368]: 2020-04-01T03:36:46.440049Z 0 [ERROR] [MY-010119] [Server] Aborting
Mar 31 22:36:46 user-desktop mysqld[7368]: 2020-04-01T03:36:46.440146Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.19) MySQL Community Server - GPL.
Mar 31 22:36:46 user-desktop systemd[1]: mysql.service: Main process exited, code=exited, status=1/FAILURE
Mar 31 22:36:46 user-desktop systemd[1]: mysql.service: Failed with result 'exit-code'.
Mar 31 22:36:46 user-desktop systemd[1]: Failed to start MySQL Community Server.

看到这是一个权限错误(在将原始目录复制到新驱动器时应该避免使用 -av 标签),我输入了以下命令以授予对整个驱动器的打开权限。
sudo chmod a+rwx /media/user/storage/

检查我输入的权限
ls -ls /media/user/storage/mysql_datadir

带输出
total 12
12 drwxrwxrwx 1 root root 12288 Mar 31 02:45 mysql

我还确保新数据目录的完整文件路径是小写的,以避免两个文件系统之间发生冲突。

我仍然无法启动 MySQL。
我会很感激任何帮助。先感谢您。

编辑:
namei -mo /media/user/storage/mysql_datadir


f: /media/user/storage/mysql_datadir
drwxr-xr-x root root /
drwxr-xr-x root root media
drwxr-x--- root root user
drwxrwxrwx root root storage
drwxrwxrwx root root mysql_datadir

最佳答案

根据您的帖子,您似乎遇到了权限问题,并且“数据目录”的所有者必须始终是 mysql。

如果它正在运行,请停止您的 mysql 服务。

考虑下面的例子:
my.cnf 看起来:

#
# Original path change to avoid space issue on server
#
datadir=/var/lib/mysql

现在您在 my.cnf 文件中更改此数据目录,例如:
#
# Original path change to avoid space issue on server
#
#datadir=/var/lib/mysql
datadir=/media/user/storage/mysql_datadir

在此之后检查权限:

cd/media/user/storage/mysql_datadir

ls -al

输出:

drwxr-x--x 40 mysql mysql 4096 Mar 27 00:01 mysql

如果没有输出,则执行以下命令:

chmod -Rf 0751/media/user/storage/mysql_datadir

chown -Rf mysql:mysql/media/user/storage/mysql_datadir

最后
现在开始你的mysql服务。

关于mysql - 在开发机器上移动 MySQL datadir,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60963415/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com