1.安装mysql5.6
docker run mysql:5.6 |
等所有项目都是Download complet 安装完毕
5.6: Pulling from library/mysql10a267c67f42: Pull complete c2dcc7bb2a88: Pull complete 17e7a0445698: Pull complete 9a61839a176f: Pull complete d4657fda01d9: Pull complete c5278a445e5d: Pull complete 197c0b76f238: Pull complete f54c5432bac4: Pull complete c26b15abee8a: Pull complete 80dbe6022c18: Pull complete 435678c09612: Pull complete Digest: sha256:84372107beb1de34bd4673049ea61bc35f374a2b4f19fd5a3abd4d0a2a50b715Status: Downloaded newer image for mysql:5.6error: database is uninitialized and password option is not specified You need to specify one of MYSQL_ROOT_PASSWORD, MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD |
2.使用本地账号创建一个文件夹用来映射docker中mysql的配置文件
其中继续创建conf、data、logs 3个文件夹
我的配置如下
val@val-linux:~/docker/mysql1$ pwd/home/val/docker/mysql1val@val-linux:~/docker/mysql1$ lsconf data logs |
3.创建mysql容器
切换到root账号进入到刚才创建的mysql1文件夹中
root@val-linux:/home/val# cd /home/val/docker/mysql1/root@val-linux:/home/val/docker/mysql1# |
创建并启动容器
docker run -p 33061:3306 --name mysql1 -v $PWD/conf:/etc/mysql -v $PWD/logs:/logs -v $PWD/data:/mysql_data -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.61用本地33061端口映射docker的3306端口 给容器命名mysql1 用本地/home/val/docker/mysql1/conf映射mysql的conf 用本地/home/val/docker/mysql1/logs映射mysql的logs 用本地/home/val/docker/mysql1/data映射mysql的mysql_data |
给root设置密码123456
4.启动mysql容器
docker start mysql11 |
5.进入mysql的bash
docker exec -it mysql1 env LANG=C.UTF-8 bash |
其中 env LANG=C.UTF-8 bash 让docker命令行支持中文
6.复制配置文件
cp /usr/my.cnf /etc/mysql/my.cnf |
7.登录mysql
mysql -u root -p |
输入密码进入
8.查看mysql编码
mysql> show variables like '%character%';+--------------------------+----------------------------+| Variable_name | Value |+--------------------------+----------------------------+| character_set_client | latin1 || character_set_connection | latin1 || character_set_database | latin1 || character_set_filesystem | binary || character_set_results | latin1 || character_set_server | latin1 || character_set_system | utf8 || character_sets_dir | /usr/share/mysql/charsets/ |+--------------------------+----------------------------+8 rows in set (0.01 sec) |
新闻热点
疑难解答