The simplest sentence
The code is as follows |
Copy Code |
>>grant all privileges on *.* to root@ "%" identified by "passwd"; >>flush privileges; |
Where "%" means that any host can log on to the server remotely. If you want to qualify only one machine to access it, replace it with the appropriate IP, and reload the permission data on the second line.
Login to MySQL
The code is as follows |
Copy Code |
# mysql-uroot-p If you cannot log in you can use Find/-name MySQL to search the MySQL program path, such as the MySQL program path:/usr/local/mysql/bin/mysql, we can log in: #/usr/local/mysql/bin/mysql-uroot-p Execute the following command: # Grant all privileges in *.* to ' root ' @ ' 192.168.0.1′identified by ' Root-password '; # flush Privileges; # exit |
192.168.0.1 is the client IP that connects to the MySQL server, and if all is specified, it is expressed in%.
It's better to be safe, we can fix it like 8.8.8.8. Only this IP can connect remotely
MySQL Remote connection permissions
It is recommended to set fixed IP2.
The code is as follows |
Copy Code |
Mysql> GRANT all privileges on *.* to root@ "8.8.8.8" identified by "root"; mysql> flush Privileges; Modify Firewall Iptables-i input-p TCP--dport 3306-j ACCEPT |
Note that the database port is not very good if it's not open.
The remote login account that opens MySQL has two big strides:
Make sure the firewall on the server does not block port 3306.
MySQL default port is 3306, you need to determine that the firewall does not block 3306 ports, or remote can not connect through 3306 ports to MySQL.
If you specified a different port when installing MySQL, open the port number that you specified in MySQL in the firewall.
If you do not know how to set up a firewall on your server, please consult your server administrator.