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

1、启动centos_sshd镜像

# docker run --net=host -d registry:/centos-sshd-:v1. /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-.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 root

mysql> UPDATE mysql.user SET Password = PASSWORD('') WHERE User = 'root';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '' 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 % of total RAM for dedicated server, else %.
# 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 = 2M
lower_case_table_names=
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
max_allowed_packet=20M
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=
character-set-server=utf8
init_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= # Recommended in standard MySQL setup
#sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES [mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

7、更改启动脚本

[root@localhost /]# vi /run.sh

#!/bin/bash
mkdir /var/run/mysqld
chgrp mysql /var/run/mysqld/
chmod g+w /var/run/mysqld/
/usr/sbin/sshd
mysqld_safe

8、重启容器

[root@localhost home]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9766bd087945 registry:/centos-sshd-:v1. "/run.sh" minutes ago Up seconds hopeful_hawking
[root@localhost home]# docker restart 9766bd087945
9766bd087945

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

[root@localhost home]# mysql -u root -p123456 -h192.168.31.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.6. MySQL Community Server (GPL) Copyright (c) , , 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 license Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> exit
Bye
[root@localhost home]# mysql -u root -p123456 -h192.168.31.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.6. MySQL Community Server (GPL) Copyright (c) , , 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 license Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
rows in set (0.00 sec) mysql>

10、提交至docker镜像,该步骤在《Docker Centos安装Openssh》中提到过,敬请移步至该文章。

Docker Centos安装Mysql5.6的更多相关文章

  1. Docker Centos安装Redis以及问题处理

    之前一篇文章 Redis安装及主从配置 介绍了redis的安装配置,另一篇文件介绍了 Docker Centos安装Openssh .今天将两篇文件结合一下——在Docker Centos环境下搭建r ...

  2. CentOS安装MySQL-5.6.10+安全配置

    注:以下所有操作均在CentOS 6.5 x86_64位系统下完成. #准备工作# 在安装MySQL之前,请确保已经使用yum安装了各类基础组件,具体见<CentOS安装LNMP环境的基础组件& ...

  3. Linux学习(一)------CentOs安装mysql5.5 数据库

    具体方法和步骤如下所示: 1.第一步就是看linu是否安装了mysql,经过rpm -qa|grep mysql查看到centos下安装了mysql5.1,那就开始卸载咯 2.接下来就是卸载mysql ...

  4. Docker - CentOS 安装 Docker 和 Docker-Compose

    目录 介绍 Docker Docker-Conpose 安装 Docker CE 系统要求 使用 YUM 安装 配置加速器 安装 Docker-Compose 介绍 Docker Docker 是一个 ...

  5. Centos安装MySQL5.6并重置密码

    数据库配置 如果用的是自带的sqllite那么数据库就可以不动 安装MySQL5.6数据库 这里强烈建议用使用5.6, 5.7版本的数据库遇见了很多BUG 安装MySQL wget http://de ...

  6. centos安装mysql5.6的正确姿态

    1.准备工作 a)卸载centos默认软件 yum remove mariadb-libs-5.5.35-3.el7.x86_64 b)安装依赖包 yum install -y perl-Module ...

  7. Docker Centos安装Openssh

    环境介绍: Docker版本:1.5.0 镜像:docker.io:centos latest 操作步骤: 1.启动镜像 docker run -ti centos /bin/bash 2.安装pas ...

  8. Docker - CentOS安装Docker

    如果要在CentOS下安装Docker容器,必须是CentOS 7 (64-bit).CentOS 6.5 (64-bit) 或更高的版本,并要求 CentOS 系统内核高于 3.10. uname ...

  9. CentOS安装mysql5.6

    1. 去官网https://dev.mysql.com/downloads/mysql/5.6.html下载mysql压缩包,选第一个,最大最全的 2. 通过FTP工具比如FileZila存放到目标地 ...

随机推荐

  1. java yum安装的环境变量设置

    如何(怎样)在CentOS 6.X 或 redhat 上使用安装JDK runtime environment (openjdk) ? CentOS 6.X 和 5.X 自带有OpenJDK runt ...

  2. Java基础——数组应用之StringBuilder类和StringBuffer类

    接上文:Java基础——数组应用之字符串String类 一.StringBuffer类 StringBuffer类和String一样,也用来代表字符串,只是由于StringBuffer的内部实现方式和 ...

  3. Java foreach

    foreach循环也叫增强型的for循环,或者叫foreach循环. foreach循环是JDK5.0的新特性(其他新特性比如泛型.自动装箱等). import java.util.Arrays; p ...

  4. 字符串拷贝函数strcpy写法_转

    Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--> ...

  5. java.net.ConnectException: Connection refused: connect

    在dos命令里输入netstat 查看下serverSocket所监听的端口有没有存在.

  6. linux:档案与目录管理

    几个常见的目录处理命令: cd(change directory):变更目录 pwd(print working directory):显示当前目录[目录为连结档,则只显示连结档的路径]([-P]不以 ...

  7. PostgreSQL index types and index bloating

    warehouse_db=# create table item (item_id integer not null,item_name text,item_price numeric,item_da ...

  8. [转] linux中常用的命令

    系统信息 arch 显示机器的处理器架构(1) uname -m 显示机器的处理器架构(2) uname -r 显示正在使用的内核版本 dmidecode -q 显示硬件系统部件 - (SMBIOS ...

  9. Java基础(61):Java单步调试(转)

    Eclipse 的单步调试 1.设置断点在程序里面放置一个断点,也就是双击需要放置断点的程序左边的栏目上. 2.调试(1)点击"打开透视图"按钮,选择调试透视图,则打开调试透视图界 ...

  10. UML: 协作图

    摘自http://www.umlonline.org/school/thread-38-1-1.html UML1.1时,协作图英文名字叫:Collaboration Diagram,UML2.0时, ...