Docker Centos安裝Mysql5.6

來源:互聯網
上載者:User

標籤:

    之前一篇隨筆《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 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、更改啟動指令碼

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

 

    8、重啟容器

[[email protected] 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     [[email protected] home]# docker restart 9766bd0879459766bd087945


    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 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[[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 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鏡像,該步驟在《Docker Centos安裝Openssh》中提到過,敬請移步至該文章。

 

Docker Centos安裝Mysql5.6

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.