denied mysql permission_mysqldump --tab (ErrCode:13-Permission denied)问题解决

在 mysql 服务器上,可以通过 load data infile ‘file_name’ into table table_name; 命令将一个文本文件中的所有数据存到指定表中。最粗略形式的例子:

load data infile ‘test.txt’ into table test_table;

默认情况下,load data infile 对于文本中行为是:

一行对应数据库表中的一条记录 各个字段之间以tab键分开 每个字段的值没有被任何字符括起来 行没有前缀可以忽略

比如某一行文本:

1 test “xx”

读入数据库之后,第三个字段的值是 “xx”,而不是 xx

就算改变了test.txt文件的访问权限,例如 chmod o+r test.txt 依然会出现上述问题。要解决这个问题会扯到 AppArmor。这是一个保护机制,限制每个程序对特定目录和文件的访问权限。也即是说,当前 mysql 程序访问这个文件的权限被 AppArmor 限制住了。关于 AppArmor 参考第二条链接(维基百科)。

真正可以做的是给mysql程序读取这个文件的权限,按照以下几个步骤可以做到:

1)打开 /etc/apparmor.d/usr.sbin.mysqld 文件

2)此时能看到很多关于mysql能够读写为目录和文件的记录,比如:

/usr/sbin/mysqld {

#Other contents

/var/log/mysql.log rw,

/var/log/mysql.err rw,

#Other contents

#This will be your dir definition

/tmp/ r,

/tmp/** rw,

#Other contents

}

在最后加上需要读写的文件的相应权限,保存并退出。

3)重新导入 AppArmor 配置,利用 /etc/init.d/apparmor reload 命令

4)重新启动 mysql,利用 service mysql restart 命令

至此问题应该解决了。不过这可能是个不安全的解决办法,需要慎重

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
为什么会这样[user_mongo@nosql01 replicaset]$ cd /opt [user_mongo@nosql01 opt]$ ll total 0 drwxr-xr-x. 3 root root 25 Mar 16 17:08 servers drwxr-xr-x. 2 root root 51 Mar 16 17:10 software [user_mongo@nosql01 opt]$ tar -zxvf /opt/software/mongodb-linux-x86_64-rhel70-4.4.12.tgz -C /opt/servers/mongodb_demo/replicaset/ mongodb-linux-x86_64-rhel70-4.4.12/LICENSE-Community.txt tar: mongodb-linux-x86_64-rhel70-4.4.12: Cannot mkdir: Permission denied tar: mongodb-linux-x86_64-rhel70-4.4.12/LICENSE-Community.txt: Cannot open: No such file or directory mongodb-linux-x86_64-rhel70-4.4.12/MPL-2 tar: mongodb-linux-x86_64-rhel70-4.4.12: Cannot mkdir: Permission denied tar: mongodb-linux-x86_64-rhel70-4.4.12/MPL-2: Cannot open: No such file or directory mongodb-linux-x86_64-rhel70-4.4.12/README tar: mongodb-linux-x86_64-rhel70-4.4.12: Cannot mkdir: Permission denied tar: mongodb-linux-x86_64-rhel70-4.4.12/README: Cannot open: No such file or directory mongodb-linux-x86_64-rhel70-4.4.12/THIRD-PARTY-NOTICES tar: mongodb-linux-x86_64-rhel70-4.4.12: Cannot mkdir: Permission denied tar: mongodb-linux-x86_64-rhel70-4.4.12/THIRD-PARTY-NOTICES: Cannot open: No such file or directory mongodb-linux-x86_64-rhel70-4.4.12/bin/install_compass tar: mongodb-linux-x86_64-rhel70-4.4.12: Cannot mkdir: Permission denied tar: mongodb-linux-x86_64-rhel70-4.4.12/bin/install_compass: Cannot open: No such file or directory mongodb-linux-x86_64-rhel70-4.4.12/bin/mongo tar: mongodb-linux-x86_64-rhel70-4.4.12: Cannot mkdir: Permission denied tar: mongodb-linux-x86_64-rhel70-4.4.12/bin/mongo: Cannot open: No such file or directory mongodb-linux-x86_64-rhel70-4.4.12/bin/mongod tar: mongodb-linux-x86_64-rhel70-4.4.12: Cannot mkdir: Permission denied tar: mongodb-linux-x86_64-rhel70-4.4.12/bin/mongod: Cannot open: No such file or directory mongodb-linux-x86_64-rhel70-4.4.12/bin/mongos tar: mongodb-linux-x86_64-rhel70-4.4.12: Cannot mkdir: Permission denied tar: mongodb-linux-x86_64-rhel70-4.4.12/bin/mongos: Cannot open: No such file or directory tar: Exiting with failure status due to previous errors [user_mongo@nosql01 opt]$ tar -zcvf /opt/software/mongodb-linux-x86_64-rhel70-4.4.12.tgz -C /opt/servers/mongodb_demo/replicaset/ tar: Cowardly refusing to create an empty archive Try `tar --help' or `tar --usage' for more information.
06-01

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值