Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use mysql Database in docker

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article to share with you is about how to use mysql database in docker, Xiaobian think it is very practical, so share it with you to learn, I hope you can gain something after reading this article, not much to say, follow Xiaobian to see it.

use

docker pull mysql

Get mysql mirror, then use

docker images

View the list of mirrors as follows

use

docker run -itd -P mysql bash

Start mysql image, docker run is the command to start the container;i is the interactive operation, t is a terminal, d means to run in the background, -P means to generate a random port locally to map mysql port 3306, mysql means to run mysql image, bash means to create an interactive shell.

use

docker ps -a

View docker images that are already running, as follows image

You can see that port 3306 of mysql mirror is bound to local port 32773, so if you want to access mysql database in docker in local area network, you need to use server IP:32773 to access it.

use the command

docker exec -it sick_hawking bash

Connect to mysql mirror,

docker exec

Docker is the connection command for the image, similar to ssh. Sick_hawking is the name of the image. Every time the image is started, it must have a name. The name can be manually specified or generated by itself.

After successful connection, as follows,

In the figure, you have entered the docker mysql image, using

service mysql status

Check mysql startup status, as follows,

mysql is not enabled and can be used

service mysql start

, as follows,

Enter mysql to verify that mysql starts successfully, as follows,

So far, mysql in docker has been successfully launched.

How to root this mysql externally?

For security, you need to set the password of the root account first, as follows

update user set authentication_string = password('root') where user = 'root';

Change the password for root to root. Then, because root execution in mysql is bound to localhost, root needs to be authorized, the code is as follows,

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION; The above is how to use mysql database in docker. Xiaobian believes that some knowledge points may be seen or used in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report