1. Get the mysql image docker pull mysql:5.6 Note: mysql5.6 is obtained here because mysql5.7 may report an error when started in centos7 2. View the mirror list docker images 3. Start the mysql image docker run -itd -P mysql:5.6 bash docker run is the command to start the container; i is interactive operation, t is a terminal, and d means running in the background. -P means generating a random port locally to map mysql port 4. View the running docker image docker ps -a From the figure, you can see that port 3306 of the mysql image is bound to the local port 32769. Therefore, if you want to access the mysql database in docker in the local area network, you need to use server IP:32769 to access it. 5. Connect to the mysql image docker exec -it relaxed_hodgkin bash docker exec is the connection command of the docker image, similar to the ssh command. relaxed_hodgkin is the name of the image. The image must have a name each time it is started. The name can be manually specified or generated by yourself. After the connection is successful, as shown below, you have entered the docker mysql image 6. Check the startup status of MySQL. The above picture shows that MySQL is not started. service mysql status 7. If mysql is not started, you can use the following command to start it. As shown in the figure, it starts successfully service mysql start 8. Enter mysql to verify whether mysql is started successfully So far, mysql in docker has been started successfully. 9. How to connect to this mysql externally using root? For security reasons, you first need to set the password for the root account, as follows update user set authentication_string = password('root') where user = 'root'; The following error will be reported at this time Because no database is selected, you need to execute the following sentence before the above command to change the use mysql; 10. Since root execution in mysql is bound to GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION; 11. Finally, use SQLyog to test the MySQL connection as follows The connection is successful, indicating that MySQL in Docker can be used in the local area network. This is the end of this article about using MySQL database in Docker to achieve LAN access. For more information about Docker operations on MySQL database, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Solution to the problem of null column in NOT IN filling pit in MySQL
>>: A brief discussion on the role of Vue3 defineComponent
1. Modify MySQL login settings: # vim /etc/my.cnf...
The hardware requirements for deploying Hyper-V a...
Three Paradigms 1NF: Fields are inseparable; 2NF:...
In MySQL, databases correspond to directories wit...
1 Download and prepare First, we need to download...
This article shares with you the graphic tutorial...
Table of contents Preface background Big guess Fi...
This article example shares the specific code of ...
The first and most important step is how to insta...
Table of contents 1. Introduction to MySQL Index ...
1. Installation environment Docker supports the f...
1. Download the software 1. Go to the MySQL offic...
1. Basic Use It can be instantiated through the M...
Table of contents Preface Enumerable properties I...
background A specific device is used to perform i...