Docker Centos安装Mysql5.6

之前一篇随笔《Docker Centos安装Openssh》 写的是如何在基础的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 root

mysql> 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 = 2M
lower_case_table_names=1
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=0
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=0

# 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、更改启动脚本

[[email protected] /]# 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、重启容器

[[email protected] home]# docker ps -a
CONTAINER ID        IMAGE                                COMMAND             CREATED             STATUS              PORTS               NAMES
9766bd087945        registry:5000/centos-sshd-222:v1.0   "/run.sh"           38 minutes ago      Up 36 seconds                           hopeful_hawking
[[email protected] home]# docker restart 9766bd087945
9766bd087945

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

[[email protected] home]# mysql -u root -p123456 -h192.168.31.203
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server 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 license

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

mysql> exit
Bye
[[email protected] home]# mysql -u root -p123456 -h192.168.31.203
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server 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 license

Type ‘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镜像,该步骤在《Docker Centos安装Openssh》中提到过,敬请移步至该文章。

时间: 2024-08-23 21:43:01

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

centos 安装mysql5.1.69

一:卸载旧版本 使用下面的命令检查是否安装有MySQL Server rpm -qa | grep mysql 有的话通过下面的命令来卸载掉 rpm -e mysql   //普通删除模式 rpm -e --nodeps mysql    // 强力删除模式,如果使用上面命令删除时,提示有依赖的其它文件,则用该命令可以对其进行强力删除 二:安装MySQL 安装编译代码需要的包 yum -y install make gcc-c++ cmake bison-devel  ncurses-devel

Docker Centos安装Redis以及问题处理

之前一篇文章 Redis安装及主从配置 介绍了redis的安装配置,另一篇文件介绍了 Docker Centos安装Openssh .今天将两篇文件结合一下——在Docker Centos环境下搭建redis缓存数据库. Redis安装及主从配置 中执行到 “2.2.4启动 redis 服务” 即可认定为redis环境搭建完毕.但是要在docker容器中搭建这些东西就不这么容易了.比如你的容器中要存在make.g++.autoconfig等环境,但是仔细想想,这些编译需要的环境在真正运行的时候并

centos安装MySQL5.7

安装环境:CentOS7 64位 MINI版,安装MySQL5.7 1.配置YUM源 在MySQL官网中下载YUM源rpm安装包:http://dev.mysql.com/downloads/repo/yum/  # 下载mysql源安装包 shell> wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm # 安装mysql源 shell> yum localinstall mysql57-commu

Docker centos 安装syslog

在通常的Linux服务器中,有一些服务本身没有日志,只能通过 tail -f /var/log/messages来查看其运行日志,比如nrpe server.但是,如果想在docker容器中实现这个功能就需要费点事了.具体步骤如下: 1.安装rsyslog # yum -y install rsyslog 2.启动syslog服务 # rsyslogd 3.测试是否在messages中生成日志 # logger "Hello World" 结果发现,在messages中只有一下一行:&

centos 安装 mysql5.7.9初始密码问题

mysql5.7.9在安装完成后会,root用户会产生一个不为空的初始密码,登陆mysql就会产生问题了,有必要修改一下登陆密码: 这是从网上找的一个方法,加以总结得出来的,亲测可以:# /etc/init.d/mysql stop # mysqld_safe --user=mysql --skip-grant-tables --skip-networking & # mysql -u root mysql mysql>update mysql.user set authentication

centos安装mysql5.6.16

1 安装包下载mysql5.6下载地址: http://dev.mysql.com/downloads/mysql/ 2 mysql的安装从官网下载的rpm64位的安装包: MySQL-5.6.16-1.linux_glibc2.5.x86_64.rpm-bundle.tar, (1)使用命令: tar xvf MySQL-5.6.16-1.linux_glibc2.5.x86_64.rpm-bundle.tar 将其解压缩,解压后的文件目录为: 看文件名就大体知道每个包是干嘛用的,不再解释.

CentOS安装MySql5.7后修改密码

MySQL5.7为root用户随机生成了一个密码,在error log中,关于error log的位置,如果安装的是RPM包,则默认是/var/log/mysqld.log. 可通过# grep "password" /var/log/mysqld.log 命令获取MySQL的临时密码 2017-03-30T07:09:55.956669Z 1 [Note] A temporary password is generated for [email protected]: NYgrcuD

Centos安装mysql5.6.33

下载安装包 百度网盘地址: 链接:https://pan.baidu.com/s/15xaHIqvjggS_rFP_jL-BVA 提取码:mh48 上传到服务器 mkdir mysql   #在/usr/local/目录下创建mysql文件夹 使用rz命令上传到/usr/local/mysql/目录下 tar -zxvf mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz  #解压 mv mysql-5.6.33-linux-glibc2.5-x86_64 mys

170425、centos安装mysql5.6数据库

# rpm -qa | grep mysql ## 查看该操作系统上是否已经安装了 mysql 数据库, 有的话,可以通过 rpm -e 命令 或者 rpm -e --nodeps 命令来卸载掉 # yum install mysql-server mysql mysql-devel # service mysqld start # chkconfig --list | grep mysqld mysqld 0:off 1:off 2:off 3:off 4:off 5:off 6:off 用上