I have a mySQL database, and I want to export a table to open in excel. I want to be doing it through PHP, so I could click a link and have the file download, but I am looking specifically for the mySQL to save the file.
For your SELECT INTO OUTFILE problem, the user you are connecting to the database with does not have privileges to create a file on the database server. See the following from the mysql manual -
The file is created on the server host, so you must have the FILE privilege to use this syntax. file_name cannot be an existing file, which among other things prevents files such as /etc/passwd and database tables from being destroyed.
The SELECT ... INTO OUTFILE statement is intended primarily to let you very quickly dump a table to a text file on the server machine. If you want to create the resulting file on some client host (meaning the client that is connecting to the database, which would be the web server/PHP) other than the server host, you cannot use SELECT ... INTO OUTFILE. In that case, you should instead use a command such as mysql -e "SELECT ..." > file_name to generate the file on the client host.