• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2138
  • Last Modified:

export/import mysql without PhpMyadmin

I was wondering if there is a way to export and import mysql database into .sql file without using PhpMyAdmin, if possible I would like to have php code to do that.
0
villechith
Asked:
villechith
  • 3
  • 3
2 Solutions
 
hernst42Commented:
See http:Q_21209155.html There a lot of links to such solutions.
0
 
ralwanCommented:
If you don't care to see the output of the shell command, then try this:

<?PHP

exec("mysqldump -u root dbname > output.sql");

?>

If you don't redirect the mysqldump command's output to a file, then your PHP script will hang until the command is done... if your PHP script timeout is not long enough, then you will get an error.

Cheers
0
 
villechithAuthor Commented:
no, I have tried it, it doesn't work.  I exported the file and import it back in using phpMyAdmin, but it said there is some error in the code.  

As for the second comment, since I'm not the admin or root, I am just a user, so I have no access to the shell.

I was looking for a very simple short php code to export not just the data structure, but also the data as well. By the way, there are so many code, I'm not sure if I use the right one, but I got the output as ".sql" , but the only thing is when I import it, there is a error.

cheers
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
ralwanCommented:
If you have a username and password that gives you access to the database, then you should be able to run the command I gave you earlier, you just have to modify it to look like this (look at your database connect statement):

<?PHP exec("mysqldump -u username -p password > output.sql"); ?>

Otherwise, if you want to do it without calling external commands, check out this following thread... someone asked the same question...

http://www.experts-exchange.com/Web/Web_Languages/PHP/PHP_Databases/Q_21106702.html

Hope this helps...
0
 
villechithAuthor Commented:
hmmmm...I don't know if it's because of me or the code or perhaps with the sql database, but I used to export both the data and structure into sql file and import it back and it worked perfectly. but when I tried hernst42's method it gave me the sql file, but only structure and when I tried to import it back in, it said error on my syntax (but why phpMyAdmin seems to work?!).

As for ralwan's method, I tried it but I don't see any file in my directory?????? did the code execute ? where is the sql file goes? perhaps wrong directory? donno...  

anyone know what's going on or have any idea?

cheers
0
 
ralwanCommented:
If you didn't specify a directory, then I think the output.sql file will just end up in the temp directory of your PHP installation... so specify a directory if you haven't already done so...

You can also try this to see if the command was giving you an error (you should see the output on the screen):

<?PHP passthru("mysqldump -u username -p password > output.sql"); ?>

Notice that I changed the command from "exec" to "passthru"...

Cheers
0
 
villechithAuthor Commented:
anyway, it doesn't really work for me, but it might work for others, that is why I dont want to keep this question open too long, so I will close it.
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now