Access mysql remote database from command line

后端 未结 17 1553
忘掉有多难
忘掉有多难 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:04

    mysql servers are usually configured to listen only to localhost (127.0.0.1), where they are used by web applications.

    If that is your case but you have SSH access to your server, you can create an ssh tunnel and connect through that.

    On your local machine, create the tunnel.

    ssh -L 3307:127.0.0.1:3306 -N $user@$remote_host
    

    (this example uses local port 3307, in case you also have mysql running on your local machine and using the standard port 3306)

    Now you should be ale to connect with

    mysql -u $user -p -h 127.0.0.1 -P 3307
    

提交回复
热议问题