how to use mysqldump with localhost:3307?

Viewed 48541

MySQL database was set up with Localhost:3307. I am trying to use mysqldump command to back up all the data from my coworker. I wrote the command line like this: mysqldump -u root -h 3307 -p database > "path_to_dumpfile\database.sql". then, I was prompted to enter the password (which is not asked anymore when I open the workbench). The problem is that, I get the following error message: "mysqldump: got error:2005: unknown mysql server host '3307' <2> when trying to connect" Is there something that I did wrong? or a step that I did not follow?

Thanks for your help.

7 Answers

Try adding --port=port_num to your command line instead of -h (or -P port_num if the former doesn't work) like so:

mysqldump -u root --port=3307 -p database > ..\path_to_dumpfile\database.sql

I'd recommend you take a look at the MySQL manual to learn of other possible arguments for the mysqldump command, link as follows.

Source: https://dev.mysql.com/doc/refman/8.0/en/mysqldump.html

As other suggested, the problem might be the use of wrong protocol when using localhost/127.0.0.1. So in addition to --port=3307 also add protocol.

Try:

--protocol=TCP --port=3307

From man mysqldump:

--protocol={TCP|SOCKET|PIPE|MEMORY}

The connection protocol to use for connecting to the server. It is useful when the other connection parameters normally would cause a protocol to be used other than the one you want. For details on the permissible values, see Section 4.2.2, “Connecting to the MySQL Server”.

I know I am late for this thread. But It can help someone in the future.

echo off 

set TIMESTAMP=%DATE:~10,4%%DATE:~4,2%%DATE:~7,2%

"C:\Program Files\MySQL\MySQLWorkbench6.3CE\mysqldump.exe" -uroot -ppassword -hlocalhost -P3307 ecommerce  > C:\Users\User\Desktop\backmeup\destination_\ecommerce.%TIMESTAMP%.sql 

As we all know, -p stands for password while -P stands for port.

For some reason, if I use spaces like -u root -p password etc., it will still give an error.

And also, using --databases won't work for me. Instead I added:

echo off 

set TIMESTAMP=%DATE:~10,4%%DATE:~4,2%%DATE:~7,2%

    "C:\Program Files\MySQL\MySQLWorkbench6.3CE\mysqldump.exe" -uroot -ppassword -hlocalhost -P3307 ecommerce  > C:\Users\User\Desktop\backmeup\destination_\ecommerce.%TIMESTAMP%.sql 
    "C:\Program Files\MySQL\MySQLWorkbench6.3CE\mysqldump.exe" -uroot -ppassword -hlocalhost -P3307 equipment_rent  > C:\Users\User\Desktop\backmeup\destination_\equipment_rent.%TIMESTAMP%.sql 

mysqldump -u usernameHere -p -h localhost --port=3306  DatabaseNameHere > FileNameHere.sql

Related