mysql’s ‘select … into outfile …’ is an easy way to export the results of a query to a file, but to execute this command you need the additional FILE privilege. The privilege is not granted by default, even with ALL, e.g.
grant ALL on exampledb.* to exampleuser;
The ALL privilege does not include FILE, so you’ll see this error:
select * from example into outfile 'test.txt'
ERROR 1045 (28000): Access denied for user 'testuser'@'%' (using password: YES)
To grant the FILE privilege,
grant FILE on *.* to exampleuser;
Note that databasename.* doesn’t appear to work, you have to grant on *.*.