How can I use MySQL command with a custom port number?

· · 9512 views

I have configured my MySQL database to utilize TCP port 3307 instead of the default 3306. I am attempting to use the mysqldump command with the following syntax:

mysqldump -u root -p database > "path_to_dumpfile\database.sql"

Upon entering the password, I encounter the following error message:

ERROR 2002 (HY000): Can't connect to MySQL server on '127.0.0.1' (36)

Is there a mistake in my approach, or have I missed a crucial step in the process?"

0
2 Answers

It seems like you are encountering an issue connecting to your MySQL server on a custom port. Here's a step-by-step guide to troubleshoot and resolve the problem:

  1. Verify MySQL Port Configuration: Ensure that your MySQL server is indeed configured to listen on port 3307. You can check this in your MySQL configuration file (usually my.cnf or my.ini). Look for the port directive and confirm it is set to 3307.

  2. Check MySQL Server Status: Confirm that your MySQL server is running and reachable. You can do this by executing the following command:

    mysqladmin -u root -p -h 127.0.0.1 -P 3307 status
    

    You will be prompted to enter your password. If the server is running, you should see information about the server status.

  3. Adjust mysqldump Command: Update your mysqldump command to explicitly specify the port with the -P option. Modify your command as follows:

    mysqldump -u root -p -P 3307 database > "path_to_dumpfile\database.sql"
    

    This ensures that mysqldump connects to the MySQL server on the correct port.

  4. Check Firewall Settings: Confirm that your firewall is not blocking connections to port 3307. If necessary, adjust your firewall rules to allow traffic on the specified port.

  5. Review MySQL User Privileges: Ensure that the MySQL user account you are using (root in this case) has the necessary privileges to connect to the MySQL server from the specified host (127.0.0.1).

After following these steps, try running the updated mysqldump command. If you encounter any further issues, review the error messages for more specific details and update your configuration accordingly.

0

To resolve the issue:

  1. Confirm MySQL is configured for port 3307.
  2. Check MySQL server status: mysqladmin -u root -p -h 127.0.0.1 -P 3307 status.
  3. Update mysqldump command: mysqldump -u root -p -P 3307 database > "path_to_dumpfile\database.sql".
  4. Ensure firewall allows connections on port 3307.
  5. Verify MySQL user privileges for root on 127.0.0.1. If issues persist, check error messages for details.
0

Please login or create new account to participate in this conversation.