“基于Alpine的mysql Docker镜像”的版本间的差异
跳到导航
跳到搜索
(→进阶) |
|||
(未显示同一用户的17个中间版本) | |||
第1行: | 第1行: | ||
− | == | + | =usage= |
+ | https://github.com/evan886/alpine-dockerbuild | ||
+ | |||
+ | <pre> | ||
+ | |||
+ | 注意 直接跑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 | ||
+ | </pre> | ||
+ | |||
+ | =mysql_secure_installation设置初始密码无效= | ||
+ | <pre> | ||
+ | 原因 | ||
+ | |||
+ | 以前的SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');已经被弃用,取而代之的是ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码'; | ||
+ | |||
+ | |||
+ | user mysql; | ||
+ | ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码'; | ||
+ | flush privileges; | ||
+ | exit; | ||
+ | |||
+ | |||
+ | 注意 授权还是这个 | ||
+ | # 4 root | ||
+ | grant all on *.* to root@'127.0.0.1' identified by 'myFD23'; | ||
+ | |||
+ | |||
+ | </pre> | ||
+ | |||
+ | [https://blog.csdn.net/Fullspeeder/article/details/111184762 mariadb通过mysql_secure_installation设置初始密码无效] | ||
+ | |||
+ | [https://blog.xzr.moe/archives/4/ mysql_secure_installation竟无效] | ||
+ | |||
+ | =进阶= | ||
+ | |||
+ | https://wiki.alpinelinux.org/wiki/Mysql#Installation_2 | ||
+ | |||
+ | |||
+ | [https://blog.csdn.net/weixin_39907713/article/details/113297602 alpine登陆mysql_基于Alpine的Docker镜像快速搭建MySQL主从] | ||
= see also= | = see also= | ||
+ | 类似的参考 | ||
+ | https://github.com/yobasystems/alpine-mariadb/blob/master/alpine-mariadb-amd64/Dockerfile | ||
+ | |||
+ | [https://blog.csdn.net/qq_43200350/article/details/100108419?utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-16.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-16.control docker创建Alpine镜像] | ||
+ | |||
+ | [https://blog.csdn.net/topwqp/article/details/52072394 mysql配置文件生效测试] | ||
=trouble shooting= | =trouble shooting= | ||
<pre> | <pre> | ||
+ | |||
+ | 我最终在Dockerfile 添加 | ||
+ | |||
+ | COPY mariadb-server.cnf /etc/my.cnf.d/mariadb-server.cnf | ||
+ | EXPOSE 3306 | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
van@myxps:~$ mysql -uroot -p -h127.0.0.1 | van@myxps:~$ mysql -uroot -p -h127.0.0.1 | ||
Enter password: | Enter password: | ||
第17行: | 第112行: | ||
[mysqld] | [mysqld] | ||
#skip-networking | #skip-networking | ||
− | |||
+ | 处理过程 其实一开始telent 3306不通就差不多是网络问题啦 , 因为容器里面是可用的 | ||
+ | 别人的解决办法 我也记录一下 虽然和我的不同 | ||
+ | 1、将 /etc/my.cnf 中的bind-address参数修改成0.0.0.0,表示允许任何ip主机访问此数据库 | ||
+ | and | ||
+ | skip-name-resolve | ||
− | + | </pre> | |
+ | |||
+ | [https://segmentfault.com/q/1010000003840346 Docker:无法连接容器中的mysql] | ||
+ | |||
+ | https://stackoverflow.com/questions/56580412/mysql-installation-for-alpine-linux-in-docker/68830928#68830928 | ||
[https://serverfault.com/questions/616696/lost-connection-to-mysql-server-at-reading-initial-communication-packet-syste Lost connection to MySQL server at 'reading initial communication packet', system error: 0 ] | [https://serverfault.com/questions/616696/lost-connection-to-mysql-server-at-reading-initial-communication-packet-syste Lost connection to MySQL server at 'reading initial communication packet', system error: 0 ] | ||
+ | |||
+ | [[category:devops]] [[category:Container]] |
2021年8月26日 (四) 06:10的最新版本
usage
https://github.com/evan886/alpine-dockerbuild
注意 直接跑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; 注意 授权还是这个 # 4 root grant all on *.* to root@'127.0.0.1' identified by 'myFD23';
mariadb通过mysql_secure_installation设置初始密码无效
进阶
https://wiki.alpinelinux.org/wiki/Mysql#Installation_2
alpine登陆mysql_基于Alpine的Docker镜像快速搭建MySQL主从
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