mac m1使用docker mysql踩坑
1、etcd版本用3.4.24
2、mysql镜像要用:mysql/mysql-server:8.0.32
3、mysql因为是8的版本,启动后本地没权限连接,需要进容器创建用户和添加权限:
# 进入容器
docker exec -it mysql容器id bash
# 运行mysql
mysql -uroot -[
# 输入密码,登录
# 操作user库
use user;
# 创建账户
CREATE USER 'root'@'%' IDENTIFIED BY '123456';
# 为创建的账户赋权
GRANT ALL ON *.* TO 'root'@'%';
# 刷新
FLUSH PRIVILEGES;
3、发现etcd也不兼容arm64版本,换了版本号3.4.24可以用
4、目前在mac上本地调试用的docker-compose.yaml:
version: '3'
services:
mysql:
container_name: mysql8
image: mysql/mysql-server:${MYSQL_VERSION}
restart: always
ports:
- ${MYSQL_PORT}:3306
environment:
TZ: Asia/Shanghai
MYSQL_ROOT_PASSWORD: 123456
MYSQL_DATABASE: zero_mall
volumes:
- ${MYSQL_DIR}/data:/var/lib/mysql
- ${MYSQL_DIR}/conf:/etc/mysql/conf.d/
- ${MYSQL_DIR}/logs:/logs
command:
--bind-address=0.0.0.0
--default-authentication-plugin=mysql_native_password
--character-set-server=utf8mb4
--collation-server=utf8mb4_general_ci
--explicit_defaults_for_timestamp=true
--lower_case_table_names=1
Etcd:
container_name: etcd3
image: bitnami/etcd:${ETCD_VERSION}
deploy:
replicas: 1
restart_policy:
condition: on-failure
environment:
- ALLOW_NONE_AUTHENTICATION=yes
privileged: true
volumes:
- ${ETCD_DIR}/data:/bitnami/etcd/data
ports:
- ${ETCD_PORT}:2379
- 2380:2380
同目录下的.env文件:
COMPOSE_PROJECT_NAME=gozero-demo-mall
ETCD_DIR=/Users/yelin/go_dev/project/src/go-zero-docker/etcd
ETCD_VERSION=3.5.7
ETCD_PORT=2379
MYSQL_VERSION=8.0.32
MYSQL_DIR=/Users/yelin/go_dev/project/src/go-zero-docker/mysql
MYSQL_PORT=3306
启动: docker-compose up -d
重启: docker-compose restart
停止删除:docker-compose down
如果mysql的配置发生变化,比如改了root密码,并不会生效,需要删除mysql配置目录文件才行,在MYSQL_DIR目录里,我是3个都删,影响暂未知
etcd也踩了好多坑,最后测试3.5.7可以启动