How to backup MySQL database on a remote server?

61,358

Solution 1

You can specify the server name as an option to mysqldump:

mysqldump --host servername dbname > dbname.sql

Solution 2

mysqldump --host hostaddress -P portnumber -u username -ppassword dbname > dbname.sql

Normally the remote port of MySQL is 3306. Here is an example:

mysqldump --host 192.168.1.15 -P 3306 -u dev -pmjQ9Y mydb > mydb.sql

Solution 3

You can use the MySQL workbench http://www.mysql.com/products/workbench/, which can backup directly to a local folder through a user-friendly interface

Solution 4

mysqldump.exe locks tables by default, so other SQL actions are not possible during a dump. Without locking any tables, use the following syntax to backup a complete remote db and dump everything on your local machine:

mysqldump -u username -p --single-transaction --quick --lock-tables=false -h ipaddress myDB > backup.sql

Change username into your own username, change ipaddress into the remote ip address, and myDB to the actual database you want to backup. This will prompt you for your password. Once provided, the dump starts.

Share:
61,358

Related videos on Youtube

john smith
Author by

john smith

Updated on May 31, 2020

Comments

  • john smith
    john smith almost 4 years

    I have a MySQL database existing on a remote server. I only have connection privilege. I don't have FTP access to the server, and I need to do a complete dump of the database. I have tried mysqldump, but the issue is that it is creating the output on the server and as I don't have FTP I can not get the output from the server.

    How can I do a clean backup and get the dump in my local machine(of course, the backup should be restored in my local machine)?

    • Barmar
      Barmar over 10 years
      I don't understand the problem. mysqldump writes the dump to standard output, and when you redirect it it goes to the local host, not the server.
    • john smith
      john smith over 10 years
      for running mysqldump i need to first login to the server, which I dont have the privilage, what I have is only a sql connection to the Mysql server
    • Barmar
      Barmar over 10 years
      mysqldump takes a --host option to access a remote server, just like the mysql command does.
  • Obmerk Kronen
    Obmerk Kronen about 10 years
    I used it many times, but was always wondering - isn't that a horrible exploit ? I mean, anyone with a host and a db name can copy a whole DB without any password ??
  • Barmar
    Barmar about 10 years
    It checks permissions just like any other use of mysql.
  • jpw
    jpw over 9 years
    One gotcha -be sure NO space after the -p PASSWORD
  • Rael Gugelmin Cunha
    Rael Gugelmin Cunha over 8 years
    And, if you have only SSH access to the server, Workbench will work too. And it's available on Ubuntu: sudo apt-get install mysql-workbench.
  • alditis
    alditis about 7 years
    man mysqldump: ... Specifying a password on the command line should be considered insecure... dev.mysql.com/doc/refman/5.7/en/password-security-user.html
  • user7082181
    user7082181 about 2 years
    that soft is garbage, I been using it for years, you always get versions issues
  • Barmar
    Barmar almost 2 years
    There could be a firewall blocking network connections to the server. Or maybe it's configured to only listen on localhost. @guitarlass