mysql数据备份

来源:互联网 发布:微软数据库软件有哪些 编辑:程序博客网 时间:2024/05/29 02:01
  1. select * from test into outfile '/home/user/test.txt'   
  2. 在linux(centos)下 ,启动了mysql 并给用户文件读写的权利  
  3. grant file on *.* to root@localhost;  
  4. 在linux系统上,目录的权限全部是 rwxrwxrwx  
  5. chmod 777 ...  
  6. /home/user/test  
  7. drwxrwxrwx 4 root root 4096 Sep 3 18:42 home  
  8. drwxrwxrwx 10 mapuser mapuser 4096 Sep 4 03:41 user  
  9. drwxrwxrwx 5 mapuser mapuser 4096 Sep 3 17:57 test  
  10. 在mysql下输入  
  11. select * from test into outfile '/home/user/test.txt'  
  12. 出现错误信息:  
  13. ERROR 1 (HY000): Can't create/write to file '/home/user/test.txt' (Errcode: 13)  
  14. 当时如果是tmp目录的话就不会有这个错误  
  15. select * from test into outfile '/tmp/test.txt'  
  16. Query OK, 0 rows test(0.00 sec)  
  17. 难道只能是tmp目录吗?  
  18. 有什么地方可以修改的吗?  
  19. 后来吧home的所有者改成了mysql  
  20. drwxrwxrwx 5 mysql mysql 4096 Sep 4 10:08 home  
  21. select * from test into outfile '/home/test.txt'  
  22. ERROR 1 (HY000): Can't create/write to file '/home/test.txt' (Errcode: 13)  
  23. 也是同样出错。  
  24. 这个有什么办法可以写入home目录下面吗?或者其他什么目录,只要不是tmp目录,有人说先写入tmp目录,再cp到想要的  
  25. 目录,这样做是可以,不过比较麻烦,文件比较大,2-3G呢,  
  26. 修改mysql的配置能实现吗?还是修改文件的权限,这个是什么问题呢?   
  27. select * from test into outfile '/tmp/test.txt'  
  28. Query OK, 0 rows test(0.00 sec)  
  29. 看一下产生的这个文件的owner 是谁。  
  30. [root@localhost /]# ls -l  
  31. drwxrwxrwx 4 root root 4096 9月 4 21:03 home  
  32. drwxrwxrwt 10 root root 4096 9月 4 21:03 tmp  
  33. [root@localhost /]# mysql  
  34. Welcome to the MySQL monitor. Commands end with ; or \g.  
  35. Your MySQL connection id is 27  
  36. Server version: 5.1.14-beta MySQL Community Server (GPL)  
  37. Type 'help;' or '\h' for help. Type '\c' to clear the buffer.  
  38. mysql> use mysql;  
  39. Reading table information for completion of table and column names  
  40. You can turn off this feature to get a quicker startup with -A  
  41. Database changed  
  42. mysql> select user from user;  
  43. +--------+  
  44. | user |  
  45. +--------+  
  46. | system |   
  47. | root |   
  48. +--------+  
  49. 2 rows in set (0.03 sec)  
  50. mysql> select user from user into outfile '/home/test.txt';  
  51. Query OK, 2 rows affected (0.02 sec)  
  52. [root@localhost home]# ls -l  
  53. -rw-rw-rw- 1 mysql mysql 12 9月 4 21:12 test.txt  
  54. [root@localhost home]# cat /home/test.txt  
  55. system  
  56. root  
  57. select * from test into outfile '/home/test.txt'  
  58. ERROR 1 (HY000): Can't create/write to file '/home/test.txt' (Errcode: 13)  
  59. ------------------------  
  60. 从Errcode: 13来看是没权限  
  61. 你执行上面语句时,是用什么用户执行的呢?检查下这个用户是否有权限吧  
  62. 估计和权限没关系,因为已经是777了。  
  63. 看看是不是selinux打开了,如果没什么特别需要的话,关了为好。  
  64. 非root用户,在mysql下执行的select * from test into outfile '/home/user/test.txt'  
  65. select * from test into outfile '/home/user/test.txt'该语句产生的文件是  
  66. -rw-rw-rw- 1 mysql mysql 12 9月 4 21:12 test.txt  
  67. mysql组的mysql用户的。  
  68. 貌似和权限没什么关系,我用root用户登陆系统,执行mysql的语句,其结果还是一样,写入/home目录时  
  69. select * from test into outfile '/home/test.txt'  
  70. ERROR 1 (HY000): Can't create/write to file '/home/test.txt' (Errcode: 13)  
  71. 还是有这个问题。  
  72. selinux会阻止其他程序写入操作??  
  73. 具体怎么改变一下selinx的配置呢  
  74. 我理清是什么问题了。  
  75. 在red hat系列的linux中selinux对哪些daemon可以进行怎么样的操作是有限制的,mysql的select into outfile的命令是mysql的daemon来负责写文件操作的。写文件之前当然要具有写文件的权限。而selinux对这个权限做了限制。如果 selinux是关闭的吧,这个命令执行是没有问题的  
  76. mysql> select user from user into outfile '/home/test.txt';  
  77. Query OK, 2 rows affected (0.02 sec)  
  78. 当时selinux开启时  
  79. selinux对mysql的守护进程mysqld进行了限制。  
  80. mysql> select user from user into outfile '/home/test.txt';  
  81. ERROR 1 (HY000): Can't create/write to file '/home/test.txt' (Errcode: 13)  
  82. 出现了没有权限写的error。  
  83. 解决方法,可以关闭selinux。  
  84. 可以在/etc/selinux中找到config  
  85. root用户,  
  86. shell>vi /etc/selinux/config  
  87. # This file controls the state of SELinux on the system.  
  88. # SELINUX= can take one of these three values:  
  89. # enforcing - SELinux security policy is enforced.  
  90. # permissive - SELinux prints warnings instead of enforcing.  
  91. # disabled - SELinux is fully disabled.  
  92. SELINUX=enforcing  
  93. 修改SELINUX=disabled关闭selinux就可以了,这个问题就可以解决了。  
  94. 不过全部关闭SELINUX有带来一些安全问题。  
  95. 当然也可以,单独给mysql的守护进程权限,  
  96. shell>getsebool -a可以查看当前的对系统一系列守护进程的权限情况。  
  97. lpd_disable_trans --> off  
  98. mail_read_content --> off  
  99. mailman_mail_disable_trans --> off  
  100. mdadm_disable_trans --> off  
  101. mozilla_read_content --> off  
  102. mysqld_disable_trans --> off  
  103. nagios_disable_trans --> off  
  104. named_disable_trans --> off  
  105. named_write_master_zones --> off  
  106. nfs_export_all_ro --> on  
  107. nfs_export_all_rw --> on  
  108. nfsd_disable_trans --> off  
  109. nmbd_disable_trans --> off  
  110. nrpe_disable_trans --> off  
  111. shell>setsebool -P mysqld_disable_trans=1  
  112. 开启对mysql守护进程的权限,这样  
  113. mysql> select user from user into outfile '/home/test.txt';  
  114. 写入到自定义的目录就没有问题了。  
  115. -P表示 是永久性设置,否则重启之后又恢复预设值。  
  116. getsebool setsebool命令在root用户下有权限。  
  117. 除了对selinux的权限,当然首先要保证该目录拥有读写权限。  
  118. 在ubuntu下 ,可以对AppArmor(/etc/apparmor.d/usr.sbin.mysqld) 修改,类似selinux。  
  119. 添加/etc/squid/lists/eighties.txt w,类似。 
原创粉丝点击