安装docker 部署mysql 并关闭大小写敏感 最详细步骤

第一步 安装docker

#安装yum 工具
yum install -y yum-utils device-mapper-persistent-data lvm2 
#设置阿里源
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo 
安装docker
yum install docker-ce
#启动docker
systemctl start docker
#设置开机启动
systemctl enable docker
设置docker镜像源
tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://qpn6e42b.mirror.aliyuncs.com"]
}
EOF
刷新
systemctl daemon-reload
systemctl restart docker
安装docker compose
yum -y install docker-compose

docker 部署mysql

# 部署mysql 并设置大小写不敏感

docker run -p 3306:3306 --name mysql -v $PWD/mysql/conf/mysql.conf.d:/etc/mysql/mysql.conf.d -v $PWD/mysql/logs:/logs -v $PWD/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=132456 -d mysql:5.7 --lower_case_table_names=1

# -lower_case_table_names=1  这句表示  创建时关闭大小写敏感

#进入容器
docker exec -it mysql bash

一、docker拷贝容器的文件到宿主机

docker cp -a 40070649f013:/etc/mysql/mysql.conf.d /data/mysql/conf/
-a 所有文件
99a5dcc8f918 容器ID
/etc/mysql/mysql.conf.d mysql配置文件目录 
/data/conf/ 宿主机目录

mysqld.cnf 文件

# Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2.0,
# as published by the Free Software Foundation.
#
# This program is also distributed with certain software (including
# but not limited to OpenSSL) that is licensed under separate terms,
# as designated in a particular file or component or in included license
# documentation.  The authors of MySQL hereby grant you an additional
# permission to link the program and your derivative works with the
# separately licensed software that they have included with MySQL.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License, version 2.0, for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA

#
# The MySQL  Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

[mysqld]
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
datadir         = /var/lib/mysql
#log-error      = /var/log/mysql/error.log
# By default we only accept connections from localhost
#bind-address   = 127.0.0.1
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

二、解决mysql无法登陆

cp 容器里面的/etc/mysql/mysql.conf.d/mysqld.cnf/mysqld.cnf 文件到宿主机
在 [mysqld] 添加语句: skip-grant-tables

重新启动MySQL服务

进入MySQL
mysql> use mysql;

修改密码
mysql> update user set password=password(“新密码”) where user=”用户名”;

如果报错:
ERROR 1054(42S22) Unknown column 'password' in 'field list'
原因: 5.7版本下的mysql数据库下已经没有password这个字段了,password字段改成了authentication_string
mysql> update user set authentication_string=password("123456") where user="root";

#刷新MySQL权限相关的表
mysql> flush privileges;
mysql> exit;

密码修改完毕

编辑mysqld.cnf(Windows下my.ini),将上面添加的内容去掉或注释(skip-grant-tables)。

重启MySQL

使用新密码登录即可

你可能感兴趣的:(docker,mysql)