docker安装mysql5.7标准版本

docker安装mysql5.7标准版本

1、centos7安装docker

[root@mysql yum.repos.d]# wget https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo

 

2、替换配置文件

[root@mysql yum.repos.d]# sed -i.bak 's#https://download.docker.com/linux/#https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/#g' /etc/yum.repos.d/docker-ce.repo

3、执行安装

yum -y install docker

4、镜像加速器配置

[root@mysql ~]# vim /etc/docker/daemon.json
{
"registry-mirrors": ["https://registry.docker-cn.com"]
}

5、docker提供数据包导入文件

链接:https://pan.baidu.com/s/1DLO8uyZJO8c4extQ8WkRzw 
提取码:g0he 
复制这段内容后打开百度网盘手机App,操作更方便哦

6、下载完毕请跟根据上传到自己路径下并导入,本人路径/opt/

docker load </opt/zst_centos7-201806.tar

7、导入成功查询方式

[root@mysql ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
zst/centos          latest              7d0b68af5a06        10 months ago       694MB

8、创建挂载逻辑卷文件目录

mkdir -p /vagrant/zst13/{mysql,data}

9、启动docker镜像

docker run -d -v /vagrant/zst13/mysql/:/opt/mysql -v /vagrant/zst13/data/:/data -v /etc/hosts:/etc/data -p1021:22 --name rhzy1 -h rhzy1 zst/centos:latest 
56e1f1b39bc6c5292496843ebfb83f281e5c1d7f2f4ab820cd13b84be08c139f

10、exec启动成功进入,ssh连接密码zstzst端口22

[root@mysql mysql]# docker exec -it rhzy1 /bin/bash
zstzst

11、创建Linux新组加入到MySQL组:

[root@rhzy1 /]# groupadd mysql

12、创建用户UID、GID用户权限

[root@rhzy1 /]# useradd -g mysql -d /usr/local/mysql -s /sbin/nologin -MN mysql

13、创建数据目录存储路径

[root@rhzy1 /]# mkdir -p /data/mysql/mysql3306/{logs,tmp,data}

14、指定MySQL软连接,为方便版本升级

[root@mysql opt]# ln -s /opt/mysql-5.7.25-linux-glibc2.12-x86_64 /usr/local/mysql

15、授权UID与GID

[root@mysql mysql]# chown -R mysql.mysql /usr/local/mysql/

16、数据目录同样授权

[root@mysql mysql]# chown -R mysql.mysql /data/

17、配置启动路径

[root@mysql mysql]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

18、写入/etc/my.cnf配置文件

[client]
port            = 3306

[mysql]
auto-rehash
prompt="\\u@\\h [\\d]>"
#pager="less -i -n -S"
#tee=/opt/mysql/query.log

[mysqld]
####: for global
user                                =mysql                          #	mysql
basedir                             =/usr/local/mysql/              #	/usr/local/mysql/
datadir                             =/data/mysql/mysql3306/data     #	/usr/local/mysql/data
server_id                           =1003306                        #	0
port                                =3306                           #	3306
character_set_server                =utf8                           #	latin1
explicit_defaults_for_timestamp     =off                            #    off
log_timestamps                      =system                         #	utc
socket                              =/tmp/mysql.sock                #	/tmp/mysql.sock
read_only                           =0                              #	off
skip_name_resolve                   =1                              #   0
auto_increment_increment            =1                              #	1
auto_increment_offset               =1                              #	1
lower_case_table_names              =1                              #	0
secure_file_priv                    =                               #	null
open_files_limit                    =65536                          #   1024
max_connections                     =1000                           #   151
thread_cache_size                   =64                             #   9
table_open_cache                    =81920                          #   2000
table_definition_cache              =4096                           #   1400
table_open_cache_instances          =64                             #   16
max_prepared_stmt_count             =1048576                        #

####: for binlog
binlog_format                       =row                          #	row
log_bin                             =/data/mysql/mysql3306/logs/mysql-bin                      #	off
binlog_rows_query_log_events        =on                             #	off
log_slave_updates                   =on                             #	off
expire_logs_days                    =7                              #	0
binlog_cache_size                   =65536                          #	65536(64k)
#binlog_checksum                     =none                           #	CRC32
sync_binlog                         =1                              #	1
slave-preserve-commit-order         =ON                             #

####: for error-log
log_error                           =/data/mysql/mysql3306/logs/error.log                        #	/usr/local/mysql/data/localhost.localdomain.err

general_log                         =off                            #   off
general_log_file                    =general.log                    #   hostname.log

####: for slow query log
slow_query_log                      =on                             #    off
slow_query_log_file                 =slow.log                       #    hostname.log
#log_queries_not_using_indexes       =on                             #    off
long_query_time                     =1.000000                       #    10.000000

####: for gtid
#gtid_executed_compression_period    =1000                          #	1000
gtid_mode                           =on                            #	off
enforce_gtid_consistency            =on                            #	off


####: for replication
skip_slave_start                     =1                              #
#master_info_repository              =table                         #	file
#relay_log_info_repository           =table                         #	file
slave_parallel_type                  =logical_clock                 #    database | LOGICAL_CLOCK
slave_parallel_workers               =4                             #    0
#rpl_semi_sync_master_enabled        =1                             #    0
#rpl_semi_sync_slave_enabled         =1                             #    0
#rpl_semi_sync_master_timeout        =1000                          #    1000(1 second)
#plugin_load_add                     =semisync_master.so            #
#plugin_load_add                     =semisync_slave.so             #
binlog_group_commit_sync_delay       =100                           #    500(0.05%秒)、默认值0
binlog_group_commit_sync_no_delay_count = 10                       #    0


####: for innodb
default_storage_engine                          =innodb                     #	innodb
default_tmp_storage_engine                      =innodb                     #	innodb
innodb_data_file_path                           =ibdata1:100M:autoextend    #	ibdata1:12M:autoextend
innodb_temp_data_file_path                      =ibtmp1:12M:autoextend      #	ibtmp1:12M:autoextend
innodb_buffer_pool_filename                     =ib_buffer_pool             #	ib_buffer_pool
innodb_log_group_home_dir                       =./                         #	./
innodb_log_files_in_group                       =3                          #	2
innodb_log_file_size                            =100M                       #	50331648(48M)
innodb_file_per_table                           =on                         #	on
innodb_online_alter_log_max_size                =128M                       #   134217728(128M)
innodb_open_files                               =65535                      #   2000
innodb_page_size                                =16k                        #	16384(16k)
innodb_thread_concurrency                       =0                          #	0
innodb_read_io_threads                          =4                          #	4
innodb_write_io_threads                         =4                          #	4
innodb_purge_threads                            =4                          #	4(垃圾回收)
innodb_page_cleaners                            =4                          #   4(刷新lru脏页)
innodb_print_all_deadlocks                      =on                         #	off
innodb_deadlock_detect                          =on                         #	on
innodb_lock_wait_timeout                        =20                         #	50
innodb_spin_wait_delay                          =128                          #	6
innodb_autoinc_lock_mode                        =2                          #	1
innodb_io_capacity                              =200                        #   200
innodb_io_capacity_max                          =2000                       #   2000
#--------Persistent Optimizer Statistics
innodb_stats_auto_recalc                        =on                         #   on
innodb_stats_persistent                         =on                         #	on
innodb_stats_persistent_sample_pages            =20                         #	20

innodb_adaptive_hash_index                      =on                         #	on
innodb_change_buffering                         =all                        #	all
innodb_change_buffer_max_size                   =25                         #	25
innodb_flush_neighbors                          =1                          #	1
#innodb_flush_method                             =                           #
innodb_doublewrite                              =on                         #	on
innodb_log_buffer_size                          =128M                        #	16777216(16M)
innodb_flush_log_at_timeout                     =1                          #	1
innodb_flush_log_at_trx_commit                  =1                          #	1
innodb_buffer_pool_size                         =100M                  #	134217728(128M)
innodb_buffer_pool_instances                    =4
autocommit                                      =1                          #	1
#--------innodb scan resistant
innodb_old_blocks_pct                           =37                         #    37
innodb_old_blocks_time                          =1000                       #    1000
#--------innodb read ahead
innodb_read_ahead_threshold                     =56                         #    56 (0..64)
innodb_random_read_ahead                        =OFF                        #    OFF
#--------innodb buffer pool state
innodb_buffer_pool_dump_pct                     =25                         #    25
innodb_buffer_pool_dump_at_shutdown             =ON                         #    ON
innodb_buffer_pool_load_at_startup              =ON                         #    ON

####  for performance_schema
performance_schema                                                      =off   #    on
performance_schema_consumer_global_instrumentation                      =on    #    on
performance_schema_consumer_thread_instrumentation                      =on    #    on
performance_schema_consumer_events_stages_current                       =on    #    off
performance_schema_consumer_events_stages_history                       =on    #    off
performance_schema_consumer_events_stages_history_long                  =off   #    off
performance_schema_consumer_statements_digest                           =on    #    on
performance_schema_consumer_events_statements_current                   =on    #    on
performance_schema_consumer_events_statements_history                   =on    #    on
performance_schema_consumer_events_statements_history_long              =on    #    off
performance_schema_consumer_events_waits_current                        =on    #    off
performance_schema_consumer_events_waits_history                        =on    #    off
performance_schema_consumer_events_waits_history_long                   =off   #    off
performance-schema-instrument                                           ='memory/%=COUNTED'

19、初始化MySQL

[root@mysql etc]# /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --initialize

20、MySQL初始密码

[root@mysql logs]# grep password error.log 
2019-04-13T14:29:00.497734+08:00 1 [Note] A temporary password is generated for root@localhost: UsDl56oDs-sc

21、启动MySQL方式:

①、单实例启动

[root@mysql logs]# /etc/init.d/mysqld [start | stop]

22、初始化报错信息解决方法

[root@rhzy1 mysql]# /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --initialize
/usr/local/mysql/bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

解决办法如下:

yum -y install libaio* libnuma.*

 

 

 

 

  • 我的微信
  • 这是我的微信扫一扫
  • weinxin
  • 我的微信公众号
  • 我的微信公众号扫一扫
  • weinxin
百度已收录
Linux

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: