docker 安装MySQL

1. docker安装略

2. 拉取镜像 docker pull mysql 

3. 准备MySQL数据目录和配置文件目录,这里以/Users/xiao/dev/mysql为例

4. 准备的mysql目录创建conf和data子目录,在conf目录里创建mysqld.cnf文件

5. mysqld.cnf 文件内容如下:

 1 # Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
 2 #
 3 # This program is free software; you can redistribute it and/or modify
 4 # it under the terms of the GNU General Public License, version 2.0,
 5 # as published by the Free Software Foundation.
 6 #
 7 # This program is also distributed with certain software (including
 8 # but not limited to OpenSSL) that is licensed under separate terms,
 9 # as designated in a particular file or component or in included license
10 # documentation.  The authors of MySQL hereby grant you an additional
11 # permission to link the program and your derivative works with the
12 # separately licensed software that they have included with MySQL.
13 #
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU General Public License, version 2.0, for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
22 
23 #
24 # The MySQL  Server configuration file.
25 #
26 # For explanations see
27 # http://dev.mysql.com/doc/mysql/en/server-system-variables.html
28 
29 [mysqld]
30 pid-file    = /var/run/mysqld/mysqld.pid
31 socket        = /var/run/mysqld/mysqld.sock
32 datadir        = /var/lib/mysql
33 #log-error    = /var/log/mysql/error.log
34 # By default we only accept connections from localhost
35 #bind-address    = 127.0.0.1
36 # Disabling symbolic-links is recommended to prevent assorted security risks
37 symbolic-links=0
38 # 独立表空间 1 开启  0 不开启(共享)
39 innodb_file_per_table=0

6. 创建并启动容器

# 9cfcce23593a 是image ID
docker run --name mysql -v /Users/xiao/dev/mysql/conf:/etc/mysql/mysql.conf.d -v /Users/xiao/dev/mysql/data:/var/lib/mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -d 9cfcce23593a

7. 检查结果

docker ps -a 

并在data目录里能看到MySQL生成的系统文件以及数据库文件

8. 启动和停止MySQL服务

1 # 启动
2 docker start mysql
3 # 停止
4 docker stop mysql
5 # 重启
6 docker restart mysql

9. 进入容器内部

docker exec -ti mysql /bin/bash

 

docker 安装MySQL

上一篇:Django-数据库--ORM


下一篇:mysql 数据库共享表空间,以及ibd文件和frm文件