Docker containers to solve the problem within the host access MySQL database server

Too lazy to describe too much, I fear, is to solve the problem, the following method of summary records, though brief, but complete, a memorial to deal with the problem of spent most of the day, and secondly, in line with the spirit of sharing to help other children encountered the problem of man, of course, this approach does not necessarily solve your problem, but how many can provide some solution ideas.

First, check the firewall, usually it should be no problem

(When the problem is I put this rule removed, found no impact, so the container, it may docker have solved the problem of the firewall, but does not exclude other people have this problem.)
Add a rule

3306 port, to a certain extent open for a specific address to ensure the security of the database 
iptables the -I the INPUT -s 172.17 . 0.2 -p tcp --dport 3306 - J ACCEPT 
shows the current rule 
iptables - the Save 
the output to a file rule 
iptables -save> iptables. rules.backup 
will rule in the file is exported to the current firewall rules take effect 
iptables -restore <iptables.rules.backup

 

Second, modify the MySQL configuration file, comment out the binding configuration, then add the database user table in the root user Host records so that the user can connect the IP address of the remote database
problems caused by:
of Can not Connect to MySQL Server ON (111 "Connection refused")
resolved:

MySQL database to find their own configuration file, and edit
/etc/mysql/mysql.conf.d# vi mysqld.cnf
will bind 127.0.0.1 commented

After opening the remote connection, there will be a second question:
"Host '172.17.0.2' IS not allowed to Connect to the this MySQL Server"

Solution:
root access to the database, perform the bottom two lines:
Grant All privileges ON * * to 'root'@'172.17.0.2' IDENTIFIED by 'pswd' with the Option Grant;.
Open to all privileges to root, as root to pswd ( not necessarily the root password, login time from 172.17.0.2 to allow all of its operations under the table all databases (* may be * changed to a particular table in a specific database only as a password at the scene) password, this random).

flush privileges;
refresh

Restart the database
/etc/init.d/mysql STOP
/etc/init.d/mysql Start


Time and then access the database from the docker will be able to
root @ 2395caf9da2b: ~ / backends the Telnet 172.17.0.1 # 3306
Trying 172.17.0.1 ...
Connected to 172.17.0.1.
Escape Character IS '^]'.


The result is that, a privilege only open IP addresses

Note that there are many well-meaning buddies online child also provides a modification of the order, grant all privileges on * * to 'root' @ '%' identified by 'pswd' with grant option.;

The IP address is changed%, this result is that as long as the root password is correct when connecting remotely from any machine, will accept, once and for all, but how many advantages such security risks, to hold their own right.

Guess you like

Origin www.cnblogs.com/haiton/p/11064727.html