mysql allow remote access from any host

Granting mysql access from remote is not secure, so it’s not recommendable but sometimes we need to do it. Here’s how to do.

  1. Login to mysql with root and create user with remote connect.
    GRANT ALL PRIVILEGES ON remote_db.* TO 'remote_user'@'%' IDENTIFIED BY 'passwordhere';
  2. We need to allow remote connection from mysql configuration. mysql.cnf or mysqld.cnf files locations are differ but in my case, it is located in /etc/mysql/mysql.conf.d/ folder.
    vi /etc/mysql/mysql.conf.d/mysqld.cnf And comment out  below line.
    #bind-address =
    After that mysql restart desired.
    service mysql restart
  3.  Now if you have any firewall or network security, allow the port. In my case, I needed to allow 3306 port in AWS inbound rule.
  4. Try to connect from remote.

    mysql -u {username} -p -h {ip address}

    mysql remote connection
    mysql remote connection