标签:版本 sea search 存储 mysql empty set ini tag
docker search -f stars=3 -f is-official=true mysql--查找tag为mysql,stars大于3官方镜像
docker pull mysql:5.7
(1)docker run -d --name mysql01 mysql:5.7
说明 此处通过查看日志(docker logs mysql01)不能正常启动,需要运行时传入指定的参数
错误提示: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 run -d -e MYSQL_ROOT_PASSWORD=password --name mysql01 mysql:5.7
docker logs mysql01
docker ps
docker exec –it mysql01 bash
mysql> CREATE USER ‘jack‘@‘localhost‘ IDENTIFIED BY ‘pwd123456‘;
mysql> GRANT ALL PRIVILEGES ON *.* TO ‘jack‘@‘localhost‘ WITH GRANT OPTION;
mysql> CREATE USER ‘jack‘@‘%‘ IDENTIFIED BY ‘pwd123456‘;
mysql> GRANT ALL PRIVILEGES ON *.* TO ‘jack‘@‘%‘
->WITH GRANT OPTION;
Key: Host上的文件系统 与 docker 容器中的文件的映射
比如:
host目录 |
mysql docker 容器目录 |
/root/Software/docker/mysql/config/my.cnf |
/etc/my.cnf |
/root/Software/docker/mysql/data |
/var/lib/mysql |
说明 host下新建的my.cnf 文件 需要初始内容
my.cnf:
[mysqld]
user=mysql
docker run -d -p 3307:3307 -v=/root/Software/docker/mysql/config/my.cnf:/etc/my.cnf -v=/root/Software/docker/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=password --name mysql01 mysql:5.7
2 bash 进入mysql01 docker容器,登入mysql 查看默认字符集
> docker exec -it mysql01 bash
>mysql –uroot –p
......
>show variables like ‘%char%’;
说明:显示为lanti字符集
my.cnf:
[mysqld]
user=mysql
character-set-server=utf8
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
>docker stop mysql01
>docker rm mysql01
docker run -d -p 3307:3307 -v=/root/Software/docker/mysql/config/my.cnf:/etc/my.cnf -v=/root/Software/docker/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=password --name mysql01 mysql:5.7
说明:配置被共享了,目的:容器删除 后数据文件也会删除, 挂载可以实现数据的持久化和共享
参考资料:
Mysql 官网:https://dev.mysql.com/doc/refman/5.7/en/docker-mysql-more-topics.html
学习群石墨文档:https://shimo.im/docs/anrlYMFEYloN52c8/
Xmind 文档 : docker的基本命令
Docker命令文档:https://docs.docker.com/engine/reference/commandline
标签:版本 sea search 存储 mysql empty set ini tag
原文地址:https://www.cnblogs.com/creasypita/p/8875955.html