MySQL doesn't allow remote connection in default setting and we need to to separate setting.
To access MySQL server remotely, firstly we need to configure the MySQL configuretion file by running
and comment the line
by adding "#".
This is to permit the IPs other than localhost to connect the MySQL server.
Then we need to grant the remote access to users within MySQL. For example, I want to grant the "root" user (password is '123456') remote access from any IP address.
You can also sepcify the IP to which you want to grant access, let's say '188.8.131.52', by
GRANT ALL PRIVILEGES ON *.* TO root@'%' IDENTIFIED BY '123456’;
Please note that if you're using amazon EC2, you also need to edit the “security group”. In the "Inbound" section, add one more rule with type “MYSQL/Aurora” and source “0.0.0.0/0” (that is “Anywhere").
GRANT ALL PRIVILEGES ON *.* TO root@'184.108.40.206' IDENTIFIED BY '123456’;