# docker pull mysql:5.7.19 5.7.19: Pulling from library/mysql 85b1f47fba49: Pull complete 27dc53f13a11: Pull complete 095c8ae4182d: Pull complete 0972f6b9a7de: Pull complete 1b199048e1da: Pull complete 159de3cf101e: Pull complete 963d934c2fcd: Pull complete f4b66a97a0d0: Pull complete f34057997f40: Pull complete ca1db9a06aa4: Pull complete 0f913cb2cc0c: Pull complete Digest: sha256:bfb22e93ee87c6aab6c1c9a4e7cdc68e9cb9b64920f28fa289f9ffae9fe8e173 Status: Downloaded newer image for mysql:5.7.19 docker.io/library/mysql:5.7.19 # docker images|grep mysql mysql 5.7.19 3e3878acd190 5 years ago 412MB
创建两个目录:
mkdir /opt/mysql/data #用于挂载mysql数据文件 mkdir /opt/mysql/conf.d #用于挂载mysql配置文件
# mkdir data # mkdir conf.d # ll 总用量 8 drwxr-xr-x 2 root root 4096 4月 25 18:44 conf.d drwxr-xr-x 2 root root 4096 4月 25 18:44 data # pwd /opt/mysql
# docker run --name mysql5.7 -p 6606:3306 -v /opt/mysql/data:/var/lib/mysql -v /opt/mysql/conf.d:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=112233 -d mysql:5.7.19 18f0f04f350dabff3d2a44b215bc795d71308d4d0769020819dd191517468240 [root@racknerd-9d3dad mysql]# docker ps -a|grep mysql 18f0f04f350d mysql:5.7.19 "docker-entrypoint.s…" 8 seconds ago Up 7 seconds 0.0.0.0:6606->3306/tcp, :::6606->3306/tcp mysql5.7
其他参数:
–restart always:开机启动 –privileged=true:提升容器内权限 -e MYSQL_USER=”marvin”:添加用户marvin -e MYSQL_PASSWORD=”pwd123”:设置marvin的密码pwd123 -e MYSQL_ROOT_PASSWORD=”rootpwd123”:设置root的密码伟rootpwd123 –character-set-server=utf8:设置字符集为utf8 –collation-server=utf8_general_ci:设置字符比较规则为utf8_general_ci
# docker exec -it mysql5.7 mysql -uroot -p112233 mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.7.19 MySQL Community Server (GPL) Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.00 sec) mysql>
mysql> grant all privileges on *.* to root@"%" identified by "root.123" with grant option; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql>
本文作者:月下追韩信
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!