当前位置:网站首页>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
边栏推荐
- GPON technical standard analysis I
- Making and using the cutting tool of TTF font library
- Instance + source code = see through 128 traps
- Why learn harmonyos and how to get started quickly?
- Select drop-down box realizes three-level linkage of provinces and cities in China
- Learn the memory management of JVM 03 - Method area and meta space of JVM
- byte2String、string2Byte
- Average lookup length when hash table lookup fails
- ZABBIX ODBC database monitoring
- Image hyperspectral experiment: srcnn/fsrcnn
猜你喜欢
About cache exceptions: solutions for cache avalanche, breakdown, and penetration
Why learn harmonyos and how to get started quickly?
Average lookup length when hash table lookup fails
Master-slave mode of redis cluster
The relationship between the size change of characteristic graph and various parameters before and after DL convolution operation
[superhard core] is the core technology of redis
MySQL transaction
Pytorch two-layer loop to realize the segmentation of large pictures
Two minutes will take you to quickly master the project structure, resources, dependencies and localization of flutter
Storage Basics
随机推荐
MySQL installation, Windows version
Get data from the database when using JMeter for database assertion
GPS数据格式转换[通俗易懂]
Seven ways to achieve vertical centering
Yum only downloads the RPM package of the software to the specified directory without installing it
What is the difference between canvas and SVG?
MySQL index - extended data
Redis's memory elimination mechanism, read this article is enough.
语义分割实验:Unet网络/MSRC2数据集
[figure neural network] GNN from entry to mastery
Matlab superpixels function (2D super pixel over segmentation of image)
Matlab label2idx function (convert the label matrix into a cell array with linear index)
ZABBIX monitors mongodb templates and configuration operations
Basic operations of MySQL data table, addition, deletion and modification & DML
Matlab boundarymask function (find the boundary of the divided area)
UNIX socket advanced learning diary -ipv4-ipv6 interoperability
SENT协议译码的深入探讨
Deep discussion on the decoding of sent protocol
Learn the memory management of JVM 02 - memory allocation of JVM
Course design of compilation principle --- formula calculator (a simple calculator with interface developed based on QT)