博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Docker Centos安装Mysql5.6
阅读量:5807 次
发布时间:2019-06-18

本文共 4000 字,大约阅读时间需要 13 分钟。

    之前一篇随笔 写的是如何在基础的centos镜像中搭建ssh服务,在此基础上再搭建其他服务。本文继续介绍在centos_ssh基础上搭建mysql服务。

 

    1、启动centos_sshd镜像

# docker run --net=host -d registry:5000/centos-sshd-222:v1.0 /run.sh

这里用的是host模式连接的网络,启动之后即可通过ssh登录到容器内部,装上mysql之后可以直接重启容器来验证是否成功。

   

    2、安装mysql

# yum install wget -y# wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm# rpm -ivh mysql-community-release-el7-5.noarch.rpm# yum install mysql-community-server

    3、配置

# mysql_install_db --user=mysql --ldata=/var/lib/mysql

    4、开启mysql

# mysqld_safe

    5、配置root用户密码、赋予root远程连接权限

        再开一个终端,进入mysql,执行如下命令:

# mysql -u rootmysql> UPDATE mysql.user SET Password = PASSWORD('123456') WHERE User = 'root';mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;mysql> flush privileges;

 

    6、更改mysql配置,使服务忽略大小写、以utf8传输等

# vi /etc/my.cnf# For advice on how to change settings please see# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html[client]default-character-set=utf8[mysqld]## Remove leading # and set to the amount of RAM for the most important data# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.# innodb_buffer_pool_size = 128M## Remove leading # to turn on a very important data integrity option: logging# changes to the binary log between backups.# log_bin## Remove leading # to set options mainly useful for reporting servers.# The server defaults are faster for transactions and fast SELECTs.# Adjust sizes as needed, experiment to find the optimal values.# join_buffer_size = 128M# sort_buffer_size = 2M# read_rnd_buffer_size = 2Mlower_case_table_names=1datadir=/var/lib/mysqlsocket=/var/lib/mysql/mysql.sockuser=mysqlmax_allowed_packet=20M# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0character-set-server=utf8init_connect='SET NAMES utf8'sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES[mysql]default-character-set=utf8# Disabling symbolic-links is recommended to prevent assorted security risks#symbolic-links=0# Recommended in standard MySQL setup#sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES[mysqld_safe]log-error=/var/log/mysqld.logpid-file=/var/run/mysqld/mysqld.pid

    7、更改启动脚本

[root@localhost /]# vi /run.sh#!/bin/bashmkdir /var/run/mysqldchgrp mysql /var/run/mysqld/chmod g+w /var/run/mysqld//usr/sbin/sshdmysqld_safe

 

    8、重启容器

[root@localhost home]# docker ps -aCONTAINER ID        IMAGE                                COMMAND             CREATED             STATUS              PORTS               NAMES9766bd087945        registry:5000/centos-sshd-222:v1.0   "/run.sh"           38 minutes ago      Up 36 seconds                           hopeful_hawking     [root@localhost home]# docker restart 9766bd0879459766bd087945

    9、验证mysql,在其余安装了mysql的服务器上执行:

[root@localhost home]# mysql -u root -p123456 -h192.168.31.203 Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 1Server version: 5.6.25 MySQL Community Server (GPL)Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.This software comes with ABSOLUTELY NO WARRANTY. This is free software,and you are welcome to modify and redistribute it under the GPL v2 licenseType 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> exitBye[root@localhost home]# mysql -u root -p123456 -h192.168.31.203 Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 2Server version: 5.6.25 MySQL Community Server (GPL)Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.This software comes with ABSOLUTELY NO WARRANTY. This is free software,and you are welcome to modify and redistribute it under the GPL v2 licenseType 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> show databases;+--------------------+| Database           |+--------------------+| information_schema || mysql              || performance_schema |+--------------------+3 rows in set (0.00 sec)mysql>

    10、提交至docker镜像,该步骤在中提到过,敬请移步至该文章。

 

转载地址:http://ehkbx.baihongyu.com/

你可能感兴趣的文章
粤出"飞龙",打造新制造广东样本
查看>>
编玩边学获数千万元A轮融资,投资方为君联资本
查看>>
开发者论坛一周精粹(第五十五期) 全站HTTPS之OSS教程 一次可以备案几个网站?...
查看>>
(干货)Linux学习资源推荐
查看>>
蓝图(Blueprint)详解
查看>>
Spark之SQL解析(源码阅读十)
查看>>
Android图片添加水印图片并把图片保存到文件存储
查看>>
C#字符串的不变性
查看>>
前端路由简介以及vue-router实现原理
查看>>
比特币系统采用的公钥密码学方案和ECDSA签名算法介绍——第二部分:代码实现(C语言)...
查看>>
分享15款很实用的 Sass 和 Compass 工具
查看>>
AMD优势: 与众不同 选择丰富
查看>>
玩转高性能超猛防火墙nf-HiPAC
查看>>
简单按日期查询mysql某张表中的记录数
查看>>
自动化部署之jenkins发布PHP项目
查看>>
C/C++编程可用的Linux自带工具
查看>>
如何判断webview是不是滑到底部
查看>>
海贼王十大悲催人物
查看>>
org.hibernate.MappingException: No Dialect mapping for JDBC type: -1 搞定!
查看>>
热点热词新闻资讯API开放接口(永久免费开放)
查看>>