How to access MySQL from a remote computer (not localhost)?

后端 未结 3 2030
执念已碎
执念已碎 2020-12-04 00:30

I have my dev environment set up as a Ubuntu Server (with LAMP installation) inside a vmware. The vmware is running on my local windows 7 machine. When I try to access my my

相关标签:
3条回答
  • 2020-12-04 00:57

    first check the ip assigned to vmware using from cmd

    ipconfig/all
    

    suppose ipassigned to vmware is 192.168.11.1 now in vmware in ubuntu check the ipadress

    ifconfig
    

    suppose ip adress of ubuntu is 192.168.11.137 now open mysql configurations

    sudo nano /etc/mysql/my.cnf change the bind address to ubuntu ip address

    bind-address = 192.168.11.137
    

    restart mysql now connect to mysql

    mysql -u root -p
    

    and create a user with all privileges and host ip of vmware i.e 192.168.11.1

    GRANT ALL ON db.* TO user@'192.168.11.1' IDENTIFIED BY 'PASSWORD';
    

    now try to connect from windows. also open port of mysql

    /sbin/iptables -A INPUT -i eth0 -p tcp --destination-port 3306 -j ACCEPT
    

    restart mysql and try to connect on ubuntu host ip address 192.168.11.137

    0 讨论(0)
  • 2020-12-04 01:05

    Ok, be aware this gives the world and his dog access to your mysql server.

    GRANT ALL ON *.* to '%'@'%' WITH GRANT OPTION;
    

    But say you are on your home network of 192.168.1.2/16 then you can at least limit it like this.

    GRANT ALL ON *.* to '%'@'192.168.%' WITH GRANT OPTION;
    

    Another option is that you have a user and password but want to connect from anywhere

    GRANT ALL ON *.* to 'mysecretuser'@'%' IDENTIFIED BY 'mysecretpassword' WITH GRANT OPTION;
    
    0 讨论(0)
  • 2020-12-04 01:05

    For Heidi SQL I was able to get it to work following the instructions on this article:

    http://mysql-tools.com/en/articles/http-tunnel/73-heidisql-a-http-tunnel.html

    It uses a program called HTTP Tunnel. It's a lot slower but at least it works. If you use Navicat it comes with a PHP file that you can upload to your server and it will connect via that.

    0 讨论(0)
提交回复
热议问题