一个80后
程序员的笔记

[Centos]用Docker安装mysql

1、安装Docker

2、安装mysql

mkdir -p /home/mysql/conf /home/mysql/data /home/mysql/logs

mkdir -p conf data logs

# mysql 8.0
sudo docker run --name mysql8 --restart=always -p 3306:3306 -p 33060:33060 -e MYSQL_ROOT_PASSWORD=admin2009 -v /data/mysql/conf:/etc/mysql/mysql.conf.d -v /data/mysql/data:/var/lib/mysql -v /data/mysql/logs:/var/log/mysql/ -d mysql:8.0

# bash

#!/usr/bin/env bash
Data_File="/data/disk/mysql/"
Passwd="admin2021"
docker run --name mysql8 \
           --restart=always \
           -p 3306:3306 \
           -p 33060:33060 \
           -e MYSQL_ROOT_PASSWORD=${Passwd} \
           -v ${Data_File}conf:/etc/mysql/mysql.conf.d \
           -v ${Data_File}data:/var/lib/mysql \
           -v ${Data_File}logs:/var/log/mysql \
           -d mysql:8.0.27


8.0安装完成后会遇见Authentication plugin 'caching_sha2_password' cannot be loaded的错误
进入容器
docker exec -it mysql bash
mysql -uroot -p
ALTER USER 'root' IDENTIFIED WITH mysql_native_password BY 'password';

# mysql 5.6
sudo docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=admin2009 -v /data/mysql/conf:/etc/mysql/mysql.conf.d -v /data/mysql/data:/var/lib/mysql -v /data/mysql/logs:/var/log/mysql/ -d mysql:5.6

docker run --name mysql57 -p 3306:3306 -e MYSQL_ROOT_PASSWORD=password -v /home/mysql57/conf:/etc/mysql/mysql.conf.d -v /home/mysql57/data:/var/lib/mysql -v /home/mysql57/logs:/var/log/mysql/ -d mysql:5.7

chown polkitd:ssh_keys logs/

3、安装好MySQL后,日常在机器上要用所以需要一个客户端

rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
yum install -y mysql-community-client

docker-compose安装

version: "3"

services:
    mysql:
      restart: always
      image: mysql:5.7
      container_name: mysql57
      volumes:
        - /data/disk/mysql/conf:/etc/mysql/mysql.conf.d
        - /data/disk/mysql/data:/var/lib/mysql
        - /data/disk/mysql/logs:/var/log/mysql
        - /data/disk/mysql/my.cnf:/etc/my.cnf
        - /data/disk/mysql/source:/docker-entrypoint-initdb.d
      environment:
        MYSQL_ROOT_PASSWORD: windows2008
        TZ: Asia/Shanghai
      ports:
        - 3306:3306

# my.cnf
[mysqld]
user=mysql
default-storage-engine=INNODB
character-set-server=utf8
character-set-client-handshake=FALSE
collation-server=utf8_unicode_ci
init_connect='SET NAMES utf8'
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
赞(14) 打赏
未经允许不得转载:笨笨天地 » [Centos]用Docker安装mysql
分享到: 更多 (0)

相关推荐

  • 暂无文章

评论 1

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏