开发者

Can I move MySQL database from Server A to Server B if all I have is FTP and MySQL user/pass for Server A?

A friend of mine wants to move his website to my Slice Host slice. The site uses a MySQL database. He gave me FTP login info, but nothing else. I have called and emailed his hosting company hoping that they would be able to give me access to PHPMyAdmin if it is installed. I have not received a response from them. Neither has my friend.

I can find the database username, password, name, etc. in the PHP files via FTP.

I tried uploading and running (in a browser) this PHP file:

$con = mysql_connect("mysql.address.com","user","password");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }

    mysql_select_db("databasename", $con);

system("mysqldump -uuser -ppassword databasename > dump.sql");

?>

...but it di开发者_如何学JAVAd not create a file named dump.sql on the server.

Any ideas on how I can accomplish my goal?


Ultimately, mysqldump isn't special. It communicates with the MySQL server just like any other client. You could write PHP code to dump each table to e.g., xml and then more code to reload them all. For most web apps, the database will just contain base tables, so you'll really only need:

SHOW DATABASES

SHOW TABLES

The above two will tell you all the tables you need to dump. You could also do a select from information_schema.tables.

SHOW CREATE TABLE «foo»

This will give you the SQL to recreate the table.

SELECT * FROM «foo»

This will (obviously) give you the data.

I'm guessing instead of writing this, you can probably find pre-existing code. phpMyAdmin has it, I believe, but that's quite a bit of complexity for just doing a quick dump...


If you have FTP and really want phpMyAdmin, why don't you install it then?


You could use mysql GUI tools using the username and password you found, but this may only work from the server (or a file on the server).

Instead of calling a system() function which you won't have access to (neither will you have mysqldump in most cases on shared hosting), use the "echo" command on an sql query, so:

$myQuery = mysql_query("show tables");

while($row = mysql_fetch_row($myQuery))
{
  echo $row[0];
}

You could also test whether the ftp username/pass gives you shell access (ssh) and try running your command from the command line as suggested in the comments

I should add its been a while since I've done php, so my code might not be quite right but you get the idea :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜