当前位置:网站首页>Install mysql using docker
Install mysql using docker
2022-08-02 02:15:00 【m0_54850825】
1. View the name of the mysql image to download on docker hub:
The docker hub image repository is for us to develop
Open the docker hub website
dockerHub official website address
Enter mysql in the search bar above
Take the image version, find the version under the tag
BackGo to the virtual machine interface and execute the following command to pull the mysql image
Do not specify the version number, download the latest version by default:
sudo docker pull mysql
Specify version number:
sudo docker pull mysql:5.7
2. After the image is pulled, use the image to create a mysql instance, and use the following command to create
sudo docker run-p 3306:3306 --name mysql-v /mydata/mysql/log:/var/log/mysql-v /mydata/mysql/data:/var/lib/mysql-v /mydata/mysql/conf:/etc/mysql-e MYSQL_ROOT_PASSWORD=root-d mysql:5.7
Here is a brief introduction to the above parameters. If you don't want to understand this piece, just copy the above command and execute it:
Configure port mapping:
-p 3306:3306--name mysql
Map port 3306 of the container to port 3306 of the host
Configure mysql data volume mount
1.-v /mydata/mysql/log:/var/log/mysql (log file mount)
Mount the log folder in the container to the /var/log/mysql folder corresponding to the host
2.-v /mydata/mysql/data:/var/lib/mysql (data file mount)
Mount the data folder in the container to the /var/lib/mysql folder corresponding to the host
3.-v /mydata/mysql/conf:/etc/mysql (configuration file mount)
Mount the configuration folder of the container to the /etc/mysql folder corresponding to the host
Note (the host mentioned here refers to the current linux host)
Configure user
-e MYSQL_ROOT_PASSWORD=root
Set the password of the initial root user
Specify the mirror resource
-d mysql:5.7
-d: run the instance in the background
mysql:5.7: specify this image to create a running instance
The following demonstration is to execute the command with the root user. If the current user is not the root user, add sudo before the command and run as an administrator
After successful creation, use the following command to view the created mysql instance:
docker ps -a
Use navicat to test whether the database is started successfully:
Username and password were set to root when docker was created just now
Click the test connection, it shows that the test is successful, indicating that the mysql instance of docker has been started normally
Finally, a small expansion, my previous blog taught you how to use vagrant to create a Linux virtual machine, if you don’t understand, you can refer to my other blog
Ultra-detailed window10 system quickly builds a Linux mirroring environment
When docker is just installed, we have to add it when executing various commandssudo, run as an administrator, which is more troublesome, we can switch to the root user when deploying the application in the docker environment:
su root
The following will pop up to enter the password:
You can enter the root user password when creating the virtual machine. If it is a virtual machine created with vagrant, the root user password is vagrant
After execution, we enter the following command to view the current user:
whoami
You can find that the user at this time has switched to root, you don't need to add sudo when executing the command again.
Let me introduce myself first. The editor graduated from Shanghai Jiaotong University in 2013. I worked in a small company and went to big factories such as Huawei and OPPO. I joined Alibaba in 2018, until now.I know that most junior and intermediate java engineers want to upgrade their skills, they often need to explore their own growth or sign up to study, but for training institutions, the tuition fee is nearly 10,000 yuan, which is really stressful.Self-learning that is not systematic is very inefficient and lengthy, and it is easy to hit the ceiling and the technology stops.Therefore, I collected a "full set of learning materials for java development" for everyone. The original intention is also very simple. I hope to help friends who want to learn by themselves but don't know where to start, and at the same time reduce everyone's burden.Add the business card below to get a full set of learning materials
边栏推荐
猜你喜欢
The first time I wrote a programming interview question for Niu Ke: input a string and return the letter with the most occurrences of the string
『网易实习』周记(一)
记一个gorm初始化的坑
Ringtone 1161. Maximum In-Layer Elements and
Outsourcing worked for three years, it was abolished...
菜刀webshell特征分析
MySQL optimization strategy
【 wheeled odometer 】
【web】理解 Cookie 和 Session 机制
Electronic Manufacturing Warehouse Barcode Management System Solution
随机推荐
¶Backtop 回到顶部 不生效
Hash collisions and consistent hashing
Multi-Party Threshold Private Set Intersection with Sublinear Communication-2021:解读
Scheduled tasks for distributed applications in Golang
【 wheeled odometer 】
Outsourcing worked for three years, it was abolished...
Yunhe Enmo: Let the value of the commercial database era continue to prosper in the openGauss ecosystem
2022 Henan Youth Training League Game (3)
The principle and code implementation of intelligent follower robot in the actual combat of innovative projects
个人博客系统项目测试
Reflex WMS Intermediate Series 7: What should I do if I want to cancel the picking of an HD that has finished picking but has not yet been loaded?
Win Go development kit installation configuration, GoLand configuration
2022-08-01 Reflection
垃圾回收器CMS和G1
Force buckle, 752-open turntable lock
Fundamentals of Cryptography: X.690 and Corresponding BER CER DER Encodings
swift项目,sqlcipher3 -> 4,无法打开旧版数据库有办法解决吗
Analysis of volatile principle
Win Go开发包安装配置、GoLand配置
LeetCode brush diary: LCP 03. Machine's adventure