ubuntu下mysql使用ntfs格式的datadir问题

作者:袖梨 2022-06-30

先叙述一下背景,本机硬盘2块,

120G SSD  = 60(linux ext4) + 60 (win7 NTFS)

2T 机械硬盘  = 600G NTFS + 600G NTFS + 700G NTFS

当初为了照顾win7对于ext分区兼容性的问题,将2T的3个分区都设为了NTFS的,如今就遇到了麻烦

由于mysql要处理大数据,SSD不够用,于是要转移datadir,开始使用的是ln的办法,但是怎么搞都不行

后来发现,ntfs分区的文件的owner不能更改,即使用chown更改了(没有报错),实际owner还是当前分区的挂载者(root)

试图解决这个问题,于是修改了fstab,将根据 /dev/sda1 这种格式的挂载改为UUID挂载,但是还是没有解决这个问题

于是改了datadir之后重启mysql总是报错,

zs@linux:/media/linux/lnRoot$ sudo /etc/init.d/mysql start
Rather than invoking init scripts through /etc/init.d, use the service(8)
utility, e.g. service mysql start

Since the script you are attempting to invoke has been converted to an
Upstart job, you may also use the start(8) utility, e.g. start mysql
start: Job failed to start

于是上网搜啊搜……………..

ntfs挂载在ubuntu下面的文件权限都是777的,具体操作过程遇到的问题和解决如下:

 1. 修改 /etc/mysql/my.cnf

 代码如下 复制代码

datadir        = /var/lib/mysql

改为

datadir        = /media/MyDocuments/mysql

 尝试重启mysql

 代码如下 复制代码

sudo /etc/init.d/mysql stop

sudo /etc/init.d/mysql start

结果mysql怎么也重启不来

 查看日志,/var/log/mysql/error.log,如下:

100819 15:10:20 [Note] Plugin 'FEDERATED' is disabled.
^G/usr/sbin/mysqld: Can't find file: './mysql/plugin.frm' (errno: 13)
100819 15:10:20 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
100819 15:10:20  InnoDB: Operating system error number 13 in a file operation.
InnoDB: The error means mysqld does not have the access rights to
InnoDB: the directory.
InnoDB: File name ./ibdata1
InnoDB: File operation call: 'open'.
InnoDB: Cannot continue operation.

查了很久,基本都是说apparmor的问题,其实这个在my.cnf里面也有提到过了,

 代码如下 复制代码
# * IMPORTANT
#   If you make changes to these settings and your system uses apparmor, you may
#   also need to also adjust /etc/apparmor.d/usr.sbin.mysqld.

ok,这样的话,就明白很多了,修改/etc/apparmor.d/usr.sbin.mysqld即可。

 代码如下 复制代码
/var/lib/mysql/ r,
/var/lib/mysql/** rwk,

改为

 代码如下 复制代码
#/var/lib/mysql/ r,
#/var/lib/mysql/** rwk,
/media/MyDocuments/mysql/ r,
/media/MyDocuments/mysql/** rwk,

再运行一下:

 代码如下 复制代码
/etc/init.d/apparmor reload

相关文章

精彩推荐