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 h
Be careful about rolling your own, unless you handle things like NULL, character sets, etc.
First alternative:
query("SELECT * FROM myTable INTO OUTFILE 'data.txt'");
$dummy = $result->fetchAll();
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 FILE SQL privilege.
Second alternative: use mysqldump to output to flat text file (as @OMG Ponies mentioned):
mysqldump -t -T
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:
mysql -B -e "SELECT * FROM MyTable" > mytable.txt
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.
- 热议问题