Access mysql remote database from command line

后端 未结 17 1600
忘掉有多难
忘掉有多难 2020-11-28 01:41

I have a server with Rackspace. I want to access the database from my local machine command line.

I tried like:

mysql -u username -h my.application.com         


        
17条回答
  •  广开言路
    2020-11-28 02:16

    this solution worked for me:

    On your remote machine (example: 295.13.12.53) has access to your target remote machine (which runs mysql server)

    ssh -f -L 295.13.12.53:3306:10.18.81.36:3306 user@295.13.12.53
    

    Explained:

    ssh -f -L your_ssh_mashine_ipaddress:your_ssh_mashine_local_port:target_ipaddress:target_port user@your_ip_address -N
    

    your_ssh_mashine_ipaddress - it is not local ip address, it is ip address that you ssh to, in this example 295.13.12.53

    your_ssh_mashine_local_port -this is custom port not 22, in this example it is 3306.

    target_ipaddress - ip of the machine that you trying to dump DB.

    target_port - 3306 this is real port for MySQL server.

    user@your_ip_address - this is ssh credentials for the ssh mashine that you connect

    Once all this done then go back to your machine and do this:

    mysqldump -h 295.13.12.53 -P 3306 -u username -p db_name > dumped_db.sql
    

    Will ask for password, put your password and you are connected. Hope this helps.

提交回复
热议问题