Problem Description:
Use nodejs to connect to the MySQL database of ECs and execute the JS file. The error is as follows:
Error: ER_HOST_NOT_PRIVILEGED: Host 'x.x.x.x' is not allowed to connect to this MySQL server
{
code: 'ER_HOST_NOT_PRIVILEGED',
errno: 1130,
sqlMessage: "Host 'x.x.x.x' is not allowed to connect to this MySQL server",
sqlState: undefined,
fatal: true
}
Solution:
This is caused by MySQL configuration that does not support remote connection. You need to connect to the server for the following configuration (log in to the root account):
mysql -u root -p
use mysql;
select host from user where user='root';
update user set host = '%' where user ='root';
// If Host = '%', it means that all IPs have connection privileges, which should be set according to the IPs of the production environment
flush privileges;