Search code examples
mysqlsqlremote-accessremote-server

connecting to MySQL server 8.0 from remote network (windows 10)


I want to have a database on my laptop and grant permissions and access to my friends so they can read/write from their home. What I have done so far:

  • Downloaded MySQL on both devices

  • set up user and granted permission on the local server using

    CREATE USER 'MyUserName'@'%' IDENTIFIED BY 'MyPassword';
    GRANT INSERT, SELECT ON *.* TO 'MyUserName'@'%';
    FLUSH PRIVILEGES;
    
  • tried finding bind-address from my.ini file but there was no such line. I ran show global variables like 'bind_address'; and I got the value * so I guess it allows remote access.

  • Restarted MySQL80 service on both devices

  • Checked that inbound firewall rules allow access to port 3306 (MySQL had already set a few rules so I left them as is)

  • Tried connecting from remote server using MySQL shell (i got the public IP from icanhazip.com)

    \connect MyUserName@<public IP for my server 92.-.-.->
    

It prompts me for the password but after I enter it I get

 MySQL Error 1045: Access denied for user 'MyUserName'@'<the IP address>' (using password: YES) 
  • I tried testing connection using powershell:

    test-netconnection -computername -port 3306

but it says:

    WARNING: TCP connect to (<IP>) : 3306) failed
    WARNING: Ping to <IP> failed with status: TimedOut 

I even tried testing connection on the same local computer with the same command (using the public and private IPs) and it failed. I'm not sure where to go from here. I have looked at other similar questions on stack but they all seem to be addressing one of these things that I have done.


Solution

  • There was one more firewall that I forgot about which was on my default gateway. To get around this it really depends on the router but what I did was:

    1. open cmd and type ipconfig and look for Default Gateway
    2. type that IP in my browser and log into my router
    3. find LAN IP Setup and reserve my IP for my device
    4. find the security options and firewall rules and have allow inbound and outbound rules to my private IP and forward the port.