当前位置:网站首页>Using MySQL in docker
Using MySQL in docker
2022-07-05 12:34:00 【just4you】
download MySQL
docker pull mysql:5.7.32
Version query : https://hub.docker.com/_/mysql?tab=tags&page=1
see Commonly used docker command
Create a mapping directory
Create directory , Used for mapping host and container , In order to save the data on the host , Not in the container .
- /usr/local/docker/mysql/conf, The configuration file
- /usr/local/docker/mysql/logs, Log files
- /usr/local/docker/mysql/data, Data files
Customize MySQL The configuration file
stay /usr/local/docker/mysql/conf Create files in directory :my.cnf. Add content
[mysql]
# Client default character set
default-character-set=utf8mb4
[mysqld]
# The character set used by the server
character-set-server=utf8mb4
init_connect='SET NAMES utf8mb4'
# The maximum number of connections allowed
max-connections=200
sql_mode ='STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
# Each data table uses a file
innodb_file_per_table=1
Configuration is set according to your actual situation
start-up & Into the container
Start the container
docker run -itd \
--name mysql \
-p 3306:3306 \
-v /usr/local/docker/mysql/conf:/etc/mysql \
-v /usr/local/docker/mysql/logs:/var/log/mysql \
-v /usr/local/docker/mysql/data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=123456 \
mysql:5.7.32
Remember to write mysql mirrored tag( The version here is 5.7.32), Otherwise docker Will automatically download the latest mysql:(
Into the container & Sign in mysql
docker exec -it mysql /bin/bash
After entering the container , Use the set password (123456) Sign in MySQL And operate
mysql -uroot -p
Test whether the configuration is effective
# Create database
create database onlinecourse default charset utf8mb4;
use onlinecourse;
# Create test table
create table t_user (
`id` char(32) not null,
`cn_name` varchar(100) default null,
primary key (`id`))
engine innodb;
Can be found in /usr/local/docker/mysql/data/onlinecourse The directory sees the file corresponding to the new table :t_user.frm, t_user.ibd
Host login mysql
The premise is that the host machine can execute mysql command .
mysql -uroot -p -h172.17.0.1
-h: Appoint MySQL Container of ip Address , This 172.17.0.1 yes docker Virtual network card IP.
Usually, it can be used on the host without setting root Account login container MySQL
common problem
- The phenomenon : Host cannot log in
- Solution : Sign in MySQL After container , Sign in mysql, Add a remotely accessible account
grant all privileges on *.* to 'akio'@'%' identified by '123321';
flush privileges;
- Log in to the host again
mysql -uakio -p -h172.17.0.1
边栏推荐
- How to recover the information server and how to recover the server data [easy to understand]
- Two minutes will take you to quickly master the project structure, resources, dependencies and localization of flutter
- Resnet18 actual battle Baoke dream spirit
- ZABBIX agent2 monitors mongodb templates and configuration operations
- MySQL function
- ZABBIX monitors mongodb (template and deployment operations)
- Pytoch counts the number of the same elements in the tensor
- Take you two minutes to quickly master the route and navigation of flutter
- Constructing expression binary tree with prefix expression
- Understanding the architecture type of mobile CPU
猜你喜欢
Two minutes will take you to quickly master the project structure, resources, dependencies and localization of flutter

Course design of compilation principle --- formula calculator (a simple calculator with interface developed based on QT)

Four operations and derivative operations of MATLAB polynomials

How can beginners learn flutter efficiently?
[email protected] (using password"/>Solve the error 1045 of Navicat creating local connection -access denied for user [email protected] (using password

嵌入式软件架构设计-消息交互

Seven ways to achieve vertical centering

MySQL splits strings for conditional queries

Master the new features of fluent 2.10

ZABBIX ODBC database monitoring
随机推荐
Take you two minutes to quickly master the route and navigation of flutter
Pytoch implements tf Functions of the gather() function
How can beginners learn flutter efficiently?
Implementing Yang Hui triangle with cyclic queue C language
Storage Basics
Learn the garbage collector of JVM -- a brief introduction to Shenandoah collector
GPS data format conversion [easy to understand]
Handwriting blocking queue: condition + lock
强化学习-学习笔记3 | 策略学习
GPS數據格式轉換[通俗易懂]
GPON technical standard analysis I
一款新型的智能家居WiFi选择方案——SimpleWiFi在无线智能家居中的应用
Get all stock data of big a
Matlab superpixels function (2D super pixel over segmentation of image)
Introduction to GNN
Redis highly available sentinel cluster
ZABBIX monitors mongodb (template and deployment operations)
Detailed steps for upgrading window mysql5.5 to 5.7.36
Learn the memory management of JVM 02 - memory allocation of JVM
Programming skills for optimizing program performance