I have a mysql table that keeps a log of messages that users send every day. What I want to do is export the the message log once per day into a text file, and am not sure how to do this. Our server has phpmyadmin, and I can export the table into a text file manually, but I don’t know how to either A) have phpmyadmin export this file automatically once per day, or B) write the exporting in php code. I want the exported files to be available to the users of my site for download. The site it written in php. If there is any other information you need to answer this question, let me know!
Share
Be careful about rolling your own, unless you handle things like NULL, character sets, etc.
First alternative:
The data.txt file will be written on the MySQL server. The directory must be writable by the uid of the mysqld process. It will not overwrite any existing file, and requires that you have the
FILESQL privilege.Second alternative: use mysqldump to output to flat text file (as @OMG Ponies mentioned):
This works like
INTO OUTFILE, it needs to run on the MySQL server host, and the directory must be writable by the mysqld uid.Third option: run query with mysql client and output text:
This can be run on any host, and requires no special privileges or directory permissions. But NULL may not be handled as it would be with mysqldump or
INTO OUTFILE.