当前位置:网站首页>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 mysqlSpecify 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.7Here 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 rootThe 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
- FOFAHUB使用测试
- 记一次gorm事务及调试解决mysql死锁
- 『网易实习』周记(一)
- 数据链路层的数据传输
- Check if IP or port is blocked
- Redis Subscription and Redis Stream
- 2022-08-01 mysql/stoonedb slow SQL-Q18 analysis
- Project Background Technology Express
- ¶ Backtop back to the top is not effective
猜你喜欢
随机推荐
AntPathMatcher使用
【ORB_SLAM2】void Frame::AssignFeaturesToGrid()
Check if IP or port is blocked
【 wheeled odometer 】
to-be-read list
Outsourcing worked for three years, it was abolished...
2022-08-01 mysql/stoonedb slow SQL-Q18 analysis
LeetCode Review Diary: 34. Find the first and last position of an element in a sorted array
[LeetCode Daily Question] - 103. Zigzag Level Order Traversal of Binary Tree
2022-08-01 安装mysql监控工具phhMyAdmin
Power button 1374. Generate each character string is an odd number
Scheduled tasks for distributed applications in Golang
工程师如何对待开源
LeetCode brushing diary: 53, the largest sub-array and
2022-08-01 反思
Centos7 install postgresql and enable remote access
『网易实习』周记(二)
nacos启动报错,已配置数据库,单机启动
2022 Henan Youth Training League Game (3)
考完PMP学什么?前方软考等着你~









