Tag Archives: Mysqldump error

Mysqldump error: tab (ErrCode:13-Permission denied) [How to Solve]

On the MySQL server, you can use load data infile ‘file_ name’ into table table_ name; Command to save all the data in a text file to the specified table. The most rough example is:
load data infile ‘test. TXT’ into table test_ table;
by default, load data infile has the following behavior for text:

A row corresponds to a record in the database table. The fields are separated by tab key. The value of each field is not enclosed by any characters. The row has no prefix and can be ignored

For example, a line of text:

1 test “xx”

after reading into the database, the value of the third field is “XX”, not XX

Even if the access permission of the test.txt file is changed, such as CHMOD O + R test.txt, the above problems will still occur. To solve this problem, it’s about AppArmor. This is a protection mechanism that limits each program’s access to specific directories and files. In other words, the permission of MySQL program to access this file is limited by AppArmor. For more information about AppArmor, refer to the second link (Wikipedia)
what you can really do is to give the MySQL program permission to read this file. Follow the following steps:
1) open the/etc/appliance.d/usr.sbin.mysqld file
2) at this time, you can see a lot of records about MySQL that can be read and written as directories and files, such as:

/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
}

At the end, add the corresponding permissions of the files that need to be read and written, save and exit
3) re import the AppArmor configuration, use the/etc/init.d/apparmor reload command
4) restart mysql, use the service MySQL restart command
so far, the problem should be solved. However, this may be an unsafe solution, which needs to be cautious