mariadb 11.1 docker 部署 系统软件 docker mysql



https://hub.docker.com/_/mariadb


docker run -d   -p 3306:3306   --name mariadb  --restart=always  --hostname mariadb  --network mgr  --ip 172.18.0.6 -e TZ='Asia/Shanghai' -v /etc/localtime:/etc/localtime:ro  -e MYSQL_ROOT_PASSWORD='wdqdmm@r'  -e MYSQL_ALLOW_EMPTY_PASSWORD='no'  -v  /data/file:/data/file/  -v /data/site/docker/env/mysql/mariadb/50-server.cnf:/etc/mysql/conf.d/50-server.cnf:ro  -v  /data/site/docker/data/mariadb:/var/lib/mysql   -v /data/file/logs/mariadb:/var/log/mysql  mariadb:latest


docker run -d  -p 3316:3306  --name mariadblabs  --restart=always   --hostname  mariadb  --network mgr  --ip 172.18.0.16  -e TZ='Asia/Shanghai' -v /etc/localtime:/etc/localtime:ro  -e MYSQL_ROOT_PASSWORD=wdqdmm@r  -e MYSQL_ALLOW_EMPTY_PASSWORD=no  -v  /data/file:/data/file/   -v /data/site/docker/env/mysql/mariadb/50-server.cnf:/etc/mysql/conf.d/50-server.cnf:ro  -v  /data/site/docker/data/mariadblabs:/var/lib/mysql   -v /data/file/logs/mariadblabs:/var/log/mysql  mariadb:latest


docker exec -it mariadb /bin/bash

docker exec -it mariadblabs /bin/bash


# 如果你的数据库中已经存在表了,建议进行修复一下

mariadbcheck -A -u'root' -p'wdqdmm@r'  --auto-repair --optimize --all-databases

mariadb-upgrade  -u'root' -p'wdqdmm@r'

# 备份

mariadb-dump -u'root' -p'wdqdmm@r'   -h'127.0.0.1' -P'3306'  --all-databases  --single-transaction  |  /usr/bin/gzip >> /data/file/mysql.sql.gz;   

-解压

gunzip mysql.sql.gz;


#获取容器ip

docker inspect mariadb |grep '"IPAddress"'

172.17.0.4


#使用--link实现两个容器互连

--link 数据库容器名:数据库容器别名

--link mariadb:mysql

-别名命名为mysql,这样在这两个容器里就可以使用“mysql”来作为提供mysql数据库服务的机器名

-不要用host主机网络, 会识别不了.


apt-get update -y

apt-mark hold tzdata

apt-get install -y wget vim net-tools curl git cron 

apt-get dist-upgrade -y 

apt-get upgrade -y 

apt autoremove    

apt clean


-e MYSQL_DATABASE=abc


# mysql-维护相关

https://abc.htmltoo.com/thread-45627.htm


# galera 集群 - docker部署

https://abc.htmltoo.com/thread-46267.htm


# 参数配置

vim  /data/docker/mysql/mariadb/50-server.cnf

#
# These groups are read by MariaDB server.
# Use it for options that only the server (but not clients) should see
# this is read by the standalone daemon and embedded servers
[server]
# this is only for the mysqld standalone daemon
[mysqld]
#
# * Basic Settings
#
#user                    = mysql
pid-file                = /run/mysqld/mysqld.pid
basedir                 = /usr
datadir                 = /var/lib/mysql
tmpdir                  = /tmp
lc-messages-dir         = /usr/share/mysql
lc-messages             = en_US
#skip-grant-tables
#skip-name-resolve
#TIMESTAMP如果没有显示声明NOT NULL,允许NULL值
explicit_defaults_for_timestamp = true
default-storage-engine = innodb
#主要用于MyISAM存储引擎,如果多台服务器连接一个数据库则建议注释下面内容
#skip-external-locking
#是否对sql语句大小写敏感,1表示不敏感
lower_case_table_names = 1
#事务隔离级别,默认为可重复读,mysql默认可重复读级别(此级别下可能参数很多间隙锁,影响性能)
transaction_isolation = READ-COMMITTED
#MySQL连接闲置超过一定时间后(单位:秒)将会被强行关闭
#MySQL默认的wait_timeout  值为8个小时, interactive_timeout参数需要同时配置才能生效
interactive_timeout = 1800
wait_timeout = 1800
# 只能用IP地址检查客户端的登录,不用主机名
skip-name-resolve
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address            = 0.0.0.0
#
# * Fine Tuning
#
#key_buffer_size        = 128M
max_allowed_packet     = 1G
#thread_stack           = 192K
#thread_cache_size      = 8
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
#myisam_recover_options = BACKUP
max_connections        = 10000
#最大连接数
max_connections = 2000
#最大错误连接数
max_connect_errors = 2000
connect_timeout         = 10
#table_cache            = 64
#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# Recommend only changing this at runtime for short testing periods if needed!
#general_log_file       = /var/log/mysql/mysql.log
#general_log            = 1
# When running under systemd, error logging goes via stdout/stderr to journald
# and when running legacy init error logging goes to syslog due to
# /etc/mysql/conf.d/mariadb.conf.d/50-mysqld_safe.cnf
# Enable this if you want to have error logging into a separate file
log_error = /var/log/mysql/error.log
# Enable the slow query log to see queries with especially long duration
slow_query_log = ON
slow_query_log_file    = /var/log/mysql/mariadb-slow.log
long_query_time        = 10
#log_slow_verbosity     = query_plan,explain
#log-queries-not-using-indexes
#min_examined_row_limit = 1000
# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
#       other settings you may need to change.

server_id              = 1
log_bin                = /var/log/mysql/mysql-bin.log
expire_logs_days        = 2
max_binlog_size        = 800M
slave_parallel_threads=2
binlog-format = row
log-slave-updates = 1
skip-slave-start = 1
log_bin_use_v1_row_events = OFF
default_authentication_plugin = mysql_native_password

#查询缓存
query_cache_type = ON
query_cache_size = 100M
#
# * SSL/TLS
#
# For documentation, please read
# https://mariadb.com/kb/en/securing-connections-for-client-and-server/
#ssl-ca = /etc/mysql/cacert.pem
#ssl-cert = /etc/mysql/server-cert.pem
#ssl-key = /etc/mysql/server-key.pem
#require-secure-transport = on
#
# * Character sets
#
# MySQL/MariaDB default is Latin1, but in Debian we rather default to the full
# utf8 4-byte character set. See also client.cnf
character-set-server  = utf8mb4
collation-server      = utf8mb4_general_ci
character_set_filesystem = utf8mb4
init_connect = 'SET collation_connection = utf8mb4_general_ci'
#设置client连接mysql时的字符集,防止乱码
init-connect = 'SET NAMES utf8mb4'
#数据库默认字符集,主流字符集支持一些特殊表情符号(特殊表情符占用4个字节)
character-set-client-handshake = FALSE
#数据库字符集对应一些排序等规则,注意要和character-set-server对应
skip-character-set-client-handshake=1   //使用服务端字符集
#
# * InnoDB
#
# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
# Read the manual for more InnoDB related options. There are many!
# Most important is to give InnoDB 80 % of the system RAM for buffer use:
# https://mariadb.com/kb/en/innodb-system-variables/#innodb_buffer_pool_size
#innodb_buffer_pool_size = 8G
# this is only for embedded server
[embedded]
# This group is only read by MariaDB servers, not by MySQL.
# If you use the same .cnf file for MySQL and MariaDB,
# you can put MariaDB-only options here
[mariadb]
# This group is only read by MariaDB-10.6 servers.
# If you use the same .cnf file for MariaDB of different versions,
# use this group for options that older servers don't understand
[mariadb-11.1]


# mysql-binlog清除

https://abc.htmltoo.com/thread-46460.htm


签名:这个人很懒,什么也没有留下!
最新回复 (0)
返回