Forum Moderators: coopster
I found this query that works on a local machine:
at
SELECT * INTO OUTFILE mysqlfile.sql FROM table
but for some reason I am not able to do this on the cpanel server with mysql version 4.025 I have even given the permission as 777 to that php file.
please help
thanks
exec("mysqldump -uUSERNAME -pPASSWORD DATABASE > file.sql");
Worked just fine for me. Replace USERNAME, PASSWORD and DATABASE with the appropriate values. Make sure you dont add a space inbetween the u and USERNAME, the p and PASSWORD, like I did.
Importing this file again using exec:
exec("mysql -hHOSTNAME uUSERNAME -pPASSWORD -DDATABASE < file.sql");
(hostname is most likely localhost, and note the extra -D infront of the databasename this time).
Hope this helps.
since I have been trying this from a long time I will let everyone know I am learning...
1. this can be done using system() in php but almost all hosting companies block that option for security.
2. the same story for exec.
3. This can also be done using the following query..
select * into outfile 'filename.sql' from tablename
however the file is saved within the mysql data folder where all the database are kept(different on linux and windows)
we can also specify the folder where the filename.sql should be kept and thats exactly what I am trying to do which is not working on the production server(RHE 3) while works fine on the local server(winXP) with same mysql server versions (4.025).
thanks for reading...I will post the solution here if I can get it somehow.
Thanks
Bye
select * into outfile $_SERVER['DOCUMENT_ROOT']."DIRECTORY_TO_HTTP/data/filename.sql" from tablename
and replace DIRECTORY_TO_HTTP with the directory to your http dir. In my case this has been "public_html" and just "http" in some cases. Make sure the "data" directory is writable though.