In the CentOS environment, after installing MySQL, root password is empty, need to set a password to use, set the password method as follows:
/usr/bin/mysqladmin-u Root Password yourpasswd
Note to replace the above command yourpasswd with their own password, this time if you use the following command to successfully log on to the MySQL terminal, the password setting is successful:
Mysql-u root-p
At this point, when you connect to MySQL remotely, you will be prompted to view the user table of the system table, and you can find that users have access only from localhost:
Mysql> Select host from user;+-----------+| Host |+-----------+| localhost |+-----------+
The "%" in host represents the remote access permission, and the following command is used to add
GRANT all privileges on * * to ' root ' @ '% ' identified by ' yourpasswd ' with GRANT OPTION;
Then the remote connection should be OK, if this time there are problems, it is likely to be a firewall problem, close iptables and so can be resolved.