Using MySQL database in docker to achieve LAN access

Using MySQL database in docker to achieve LAN access

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 3306 , mysql means running the mysql image, and bash means creating an interactive shell.

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 root password root .

use mysql;

10. Since root execution in mysql is bound to localhost , root needs to be authorized

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:
  • Detailed explanation of Deepin using docker to install mysql database
  • Detailed explanation of psql database backup and recovery in docker
  • Database backup in docker environment (postgresql, mysql) example code
  • Implementation code for using mongodb database in Docker
  • Detailed explanation of using MySQL database in docker (access in LAN)
  • Detailed explanation of using mongodb database in docker (access in LAN)
  • Detailed explanation of installing and configuring Oracle database in Docker
  • PHP based on Docker calls Mysql database based on Docker
  • How to initialize the Mysql database when the Docker container starts
  • What are the drawbacks of deploying the database in a Docker container?

<<:  Solution to the problem of null column in NOT IN filling pit in MySQL

>>:  A brief discussion on the role of Vue3 defineComponent

Recommend

How to change mysql password under Centos

1. Modify MySQL login settings: # vim /etc/my.cnf...

Steps to deploy hyper-V to achieve desktop virtualization (graphic tutorial)

The hardware requirements for deploying Hyper-V a...

Mysql database design three paradigm examples analysis

Three Paradigms 1NF: Fields are inseparable; 2NF:...

MySQL database case sensitivity issue

In MySQL, databases correspond to directories wit...

Tutorial on installing Tomcat server under Windows

1 Download and prepare First, we need to download...

Implementing license plate input function in WeChat applet

Table of contents Preface background Big guess Fi...

Token verification login in Vue project (front-end part)

This article example shares the specific code of ...

Detailed explanation of MySQL database index

Table of contents 1. Introduction to MySQL Index ...

Docker installation tutorial in Linux environment

1. Installation environment Docker supports the f...

Detailed tutorial on installation and configuration of MySql 5.7.17 winx64

1. Download the software 1. Go to the MySQL offic...

Details of MutationObServer monitoring DOM elements in JavaScript

1. Basic Use It can be instantiated through the M...

Detailed discussion of the differences between loops in JavaScript

Table of contents Preface Enumerable properties I...

Using nginx + fastcgi to implement image recognition server

background A specific device is used to perform i...