Hello,
I have installed the OpenVPN server on the box and on the same box MySQL is hosted. Now if I try to connect to MySQL instance the following error appears.
“Lost Connection to MySQL server at ‘reading initial communication packet’ system error 0”
I have added the public IP of VPN in MySQL Access Host in WHM and cPanel nothing seems to work.

I did this because in Pakistan we have dynamic IPs so I would not let everyone try to hit the MySQL instance rather the access is given only to the VPN IP.
Thanks

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
1 answer

Hello, @hazhayder

Could you please provide us with the content of the MySQL configuration file? If you’ve binded the MySQL to localhost you can try to comment out the following line and then restart the MySQL service:

from

bind-address = 127.0.0.1

to

#bind-address = 127.0.0.1

Hope this helps!

Regards,
Alex

  • This is the current my.cnf file.

    [mysqld]
    performance-schema=0
    log-error=/var/lib/mysql/centos7.template.liquidweb.com.err
    innodb_file_per_table=1
    default-storage-engine=innodb
    innodb_buffer_pool_size=128M
    innodb_log_file_size=128M
    max_connections=300
    key_buffer_size = 8M
    max_allowed_packet=268435456
    open_files_limit=10000
    
    • Hello, @hazhayder

      Thanks for sharing this, as far as I can see you don’t have the bind-address option in the config file so this one is checked.

      Can you examine the MySQL error_log file and see if there is a more detailed error that can help us with the troubleshooting?

      You can check the last 100 entries in the log:

      tail -n 100 /path-to-the-error-log-file.err

      you can get the full path with this command:

      grep "log-error" /etc/my.cnf

      You can also check if the MySQL service is currently still running or stuck:

      ps aux | grep mysql

      and also:

      netstat -plunt | grep mysqld

      or

      netstat -plunt | grep 3306

      Can you confirm if you’ve followed the listed steps from this tutorial as well? This can help me to see what may have gone wrong with the MySQL service.

      https://www.digitalocean.com/community/tutorials/how-to-set-up-and-configure-an-openvpn-server-on-centos-7

      Regards,
      Alex

      by Jacob Tomlinson
      Here we'll install and configure OpenVPN on a CentOS 7 server. We'll also discuss how to connect a client to the server on Windows, OS X, and Linux. OpenVPN is an open-source VPN application that lets you create and join a private network securely over the public Internet.
      • Hey Alex,
        Thanks for your reply. I figured this out so actually when VPN is running my browsing IP is only changed to the VPN server’s IP. While the native application still runs on the real IP address. I got to know about this after I tried to logging into MySQL from MySQL workbench and checking into error log showed me my real IP Address.
        What is the work around for this?
        Regards,
        Hasnain

        • Hello, @hazhayder

          I believe you can still access the database with MySQL workbench when using the VON. You can check the image bellow with the configured settings:

          See this image

          Also if you’re using any Firewall configuration within WHM/cPanel you make sure that the VPN IP address is enabled.

          Let me know how it goes.

          Regards,
          Alex

Submit an Answer