The mysqldump
command in MySQL is used to create backups of MySQL databases. One of the options available is --bind-address=name
, which allows you to specify the IP address from which mysqldump connects to MySQL server. This is particularly useful in scenarios where MySQL server is configured to listen on specific IP addresses or interfaces.
Here are several examples demonstrating the usage of --bind-address=name
with mysqldump
:
Example 1: Backup a database from a specific IP address.
mysqldump --bind-address=192.168.1.100 -u root -p mydatabase > backup.sql
This command connects to the MySQL server from the IP address 192.168.1.100 and dumps the database mydatabase
to backup.sql
.
Example 2: Backup all databases from localhost only.
mysqldump --bind-address=localhost -u root -p --all-databases > alldatabases.sql
Using --bind-address=localhost
ensures that mysqldump connects only via the localhost address, even if MySQL is configured to listen on multiple addresses.
Example 3: Backup using a hostname.
mysqldump --bind-address=db.example.com -u root -p mydatabase > backup.sql
Here, --bind-address=db.example.com
specifies connecting to the MySQL server from the hostname db.example.com
.
Example 4: Backup from a specific network interface.
mysqldump --bind-address=eth0 -u root -p mydatabase > backup.sql
This command connects via the network interface eth0
to perform the database backup.
Example 5: Backup with IPv6 address.
mysqldump --bind-address=2001:db8::1 -u root -p mydatabase > backup.sql
Using an IPv6 address like 2001:db8::1
ensures mysqldump connects via IPv6 to the MySQL server.
Example 6: Backup using a fully qualified domain name (FQDN).
mysqldump --bind-address=db.example.com -u root -p mydatabase > backup.sql
Connects to MySQL server using the FQDN db.example.com
as the binding address.
Example 7: Backup with a specific local IP address.
mysqldump --bind-address=127.0.0.1 -u root -p mydatabase > backup.sql
Using 127.0.0.1
ensures that the backup is performed locally, ideal for secure local backups.
Example 8: Backup from a Docker container.
mysqldump --bind-address=docker-container-name -u root -p mydatabase > backup.sql
Connects to MySQL server from within a Docker container named docker-container-name
.
Example 9: Backup using a virtual IP address.
mysqldump --bind-address=10.0.2.5 -u root -p mydatabase > backup.sql
Connects using a virtual IP address 10.0.2.5
configured on the system.
Example 10: Backup with a loopback address.
mysqldump --bind-address=::1 -u root -p mydatabase > backup.sql
This command uses the IPv6 loopback address ::1
to connect to MySQL locally.
Verification Steps: After executing any of the above commands, you can verify if the backup file backup.sql
or alldatabases.sql
(depending on the example) is created in the current directory. Additionally, you can check the content of the backup file to ensure it contains the expected SQL dump of the specified database(s).
Read Also
Applying Slave Statements in mysqldump (Deprecated)
Apply Replica Statements in mysqldump Output
Allowing Keywords as Column Names in mysqldump Output
Include Locks around INSERT Statements in mysqldump
Adding DROP TRIGGER Statements in mysqldump Output
Discussion about this post