基于Alpine的mysql Docker镜像
跳到导航
跳到搜索
usage
注意 直接跑docker docker run -it --name mysql 会再次生成mariadb.conf 小心 数据库文件就是当前目录的mysql cat .env # Environment variables for docker-compose command ALPINE_VERSION=3.14 IMAGE_NAME=evan886/mariadb-alpine # Running CONTAINER_NAME=mysql MYSQL_ROOT_PASSWORD=root2240881 MYSQL_USER=evan MYSQL_PASSWORD=evanlai36 MYSQL_DATABASE=admin HOST_ADDRESS=3306 cat docker-compose.yml version: '2' services: mysql: image: ${IMAGE_NAME}:${ALPINE_VERSION} container_name: ${CONTAINER_NAME} environment: - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD} - MYSQL_USER=${MYSQL_USER} - MYSQL_PASSWORD=${MYSQL_PASSWORD} - MYSQL_DATABASE=${MYSQL_DATABASE} volumes: - .:/app ports: - "${HOST_ADDRESS}:3306" restart: always # restart 动作在debian11 好像不起效果 docker-compose up -d mysql -uroot -p -h127.0.0.1
mysql_secure_installation设置初始密码无效
原因 以前的SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');已经被弃用,取而代之的是ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码'; user mysql; ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码'; flush privileges; exit;
mariadb通过mysql_secure_installation设置初始密码无效
see also
类似的参考 https://github.com/yobasystems/alpine-mariadb/blob/master/alpine-mariadb-amd64/Dockerfile
trouble shooting
我最终在Dockerfile 添加 COPY mariadb-server.cnf /etc/my.cnf.d/mariadb-server.cnf EXPOSE 3306 van@myxps:~$ mysql -uroot -p -h127.0.0.1 Enter password: ERROR 2013 (HY000): Lost connection to MySQL server at 'handshake: reading initial communication packet', system error: 11 解决办法 注释掉这行 skip-networking 跳过TCP/IP连接 cat /etc/my.cnf.d/mariadb-server.cnf [mysqld] #skip-networking 处理过程 其实一开始telent 3306不通就差不多是网络问题啦 , 因为容器里面是可用的 别人的解决办法 我也记录一下 虽然和我的不同 1、将 /etc/my.cnf 中的bind-address参数修改成0.0.0.0,表示允许任何ip主机访问此数据库 and skip-name-resolve
Lost connection to MySQL server at 'reading initial communication packet', system error: 0