1, 下载镜像, 我用的是8
docker pull mysql:8.0.11
2, 启动镜像
docker run --name mysql8 -p 3306:3306 -v /Users/wenbronk/Containers/Data/mysql/data:/var/lib/mysql -v /Users/wenbronk/Containers/Data/mysql/log:/var/log/mysql -v /Users/wenbronk/Containers/Data/mysql/my.cnf:/etc/mysql/my.cnf:rw -e MYSQL_ROOT_PASSWORD=a75767626 --restart=always -d mysql:8.0.16
my.cnf的内容
[mysqld] pid-file = /var/run/mysqld/mysqld.pid socket = /var/run/mysqld/mysqld.sock datadir = /var/lib/mysql secure-file-priv= NULL # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # Custom config should go here !includedir /etc/mysql/conf.d/ default_authentication_plugin= mysql_native_password
default_authentication_plugin= mysql_native_password (这个是因应mysql8的安全机制升级而需要修改的配置,不配置的话将无法登录管理)
3, 连接进入mysql
docker run -it --link mysql8:mysql --rm mysql sh -c 'exec mysql -h"$MYSQL_PORT_3306_TCP_ADDR" -P"$MYSQL_PORT_3306_TCP_PORT" -uroot -p"$MYSQL_ENV_MYSQL_ROOT_PASSWORD"'
4, 通过docker-compse部署(未试用, 粘贴备用), 详见: https://hub.docker.com/_/mysql/
stack.yml
# Use root/example as user/password credentials version: '3.1' services: db: image: mysql restart: always environment: MYSQL_ROOT_PASSWORD: example adminer: image: adminer restart: always ports: - 8080:8080
5, 开箱即用, 不需要 更改远程登陆
use mysql;
select host, user, authentication_string, plugin from user;
GRANT ALL ON *.* TO 'root'@'%';
flush privileges;
https://blog.csdn.net/xinpengfei521/article/details/80403965
2, 之后, 发现版本太新, 好多东西和公司的不兼容, 在装个5.7吧...
1, 下载
docker pull mysql:5.7.27
2, 启动
docker run --name mysql5.7 -p 3306:3306 -v /Users/wenbronk/Containers/Data/mysql5.7/data:/var/lib/mysql -v /Users/wenbronk/Containers/Data/mysql5.7/log:/var/log/mysql -v /Users/wenbronk/Containers/Data/mysql5.7/my.cnf:/etc/mysql/my.cnf:rw -e MYSQL_ROOT_PASSWORD=a75767626 --restart=always -d mysql:5.7.27
my.cnf的配置
[client] default-character-set=utf8 [mysql] default-character-set=utf8 [mysqld] init_connect='SET collation_connection = utf8_unicode_ci' init_connect='SET NAMES utf8' character-set-server=utf8 collation-server=utf8_unicode_ci skip-character-set-client-handshake
主要用来更改字符集等
3, 链接进mysql
docker run -it --link mysql5.7:mysql --rm mysql:5.7.27 sh -c 'exec mysql -h"$MYSQL_PORT_3306_TCP_ADDR" -P"$MYSQL_PORT_3306_TCP_PORT" -uroot -p"$MYSQL_ENV_MYSQL_ROOT_PASSWORD"'
4, 开箱即用, 不需要 远程登陆等授权
SET PASSWORD = PASSWORD('root');
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT option;
flush PRIVILEGES;
新建用户等
CREATE USER 'resthome'@'%' IDENTIFIED BY 'uuU89890Jkfdsd8934jlkjf'; grant all privileges on 想授权的数据库.* to 'user1'@'%';
https://hub.docker.com/_/mysql/