mysql移动目录后不可用的问题

How to change selinux when moving the default location (/var/lib/mysql).

In the default directory (/var/lib/mysql)
Run ls -lZ /var/lib/mysql
(ls is the selinux list function to detail the labels for each object.

This is the default directory and will list these objects.
drwx------. mysql mysql unconfined_u:object_r:mysqld_db_t:s0 mysql

This shows that mysqld_db_t is the default selinux context for the directory. Naturally when you move to a new location that directory context will be different. You have to add that to the object list for selinux to make it work.

The new directory I created was /mnt/data/sqldata

When I do a ls -LZ in the new location.
drwxr-xr-x. mysql mysql unconfined_u:object_r:usr_t:s0 sqldata

ug...not a mysql directory label. Have to do something about that!

Type:
semanage fcontext -a -t mysqld_db_t "/mnt/data/sqldata(/.*)?"

This adds an entry to the selinux context file.

/etc/selinux/targeted/contexts/files/file_contexts.local
This is where the file is located. In it you'll see

/mnt/data/sqldata(/.*)? system_u:object_r:mysqld_db_t:s0

But...to write it to the disk, you need an additional command.

restorecon -R -v /mnt/data/sqldata

Now when you do a ls -Z you'll see the new labels and be able to start up mysql and have it work.

ls -lZ /opt
drwxr-xr-x. mysql mysql system_u:object_r:mysqld_db_t:s0 mysql

Ya!
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值