温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Docker中怎么构建Mariadb

发布时间:2022-02-16 15:18:00 来源:亿速云 阅读:193 作者:iii 栏目:开发技术

这篇文章主要介绍“Docker中怎么构建Mariadb”,在日常操作中,相信很多人在Docker中怎么构建Mariadb问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”Docker中怎么构建Mariadb”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

Docker中怎么构建Mariadb

获取mariadb镜像地址

root@debian1:~/nginx# docker search mariadb NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mariadb MariaDB is a community-developed fork of M… 1417 [OK]
bitnami/mariadb Bitnami MariaDB Docker Image 39 [OK]

拉去maridb的最新镜像

root@debian1:~/nginx# docker pull mariadb
Using default tag: latest
latest: Pulling from library/mariadb

启动,mariadb镜像

root@debian1:~/nginx# docker run –privileged -d -e TIMEZONE=Asis/Shanghai -e MYSQL_ROOT_PASSWORD=hanye131 -e SERVER_ID=1 -v $PWD/mysql_db:/var/lib/mysql -p 3306:3306 mariadb
255650e5e83d27402b1df338c09c0639b1512e73ef27cd31e1f2c90509dc104c
root@debian1:~/nginx# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
255650e5e83d mariadb “docker-entrypoint…” 3 seconds ago Up 1 second 0.0.0.0:3306->3306/tcp festive_ride

查看启动占用的端口

root@debian1:~/nginx# netstat -tunl|grep 3306
tcp6 0 0 :::3306 :::* LISTEN

链接docker的mysql

root@debian1:~/nginx# mysql -uroot -phanye131 -h227.0.0.1 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 5.5.5-10.2.6-MariaDB-10.2.6+maria~jessie mariadb.org binary distributionCopyright (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>

错误解决方案

如果提示无法链接找到sock文件,你需要链接到docker的mariadb容器之内来授权链接

链接到docker mariadb之内

获取mariadb的CONTAINER ID

root@debian1:~/nginx# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
255650e5e83d mariadb “docker-entrypoint…” 10 minutes ago Up 10 minutes 0.0.0.0:3306->3306/tcp festive_ride 360baf71efb0 a3ae0b27ec04 “/run.sh bash” 3 hours ago Exited (2) 3 hours ago nginx

我这里的mariadb的镜像的CONTAINER ID是 255650e5e83d

登录mariadb之内

root@debian1:~/nginx# docker exec -it 255650e5e83d bash
root@255650e5e83d:/#

授权mysql的root用户的链接权限(其通用户同样设置)

MariaDB [(none)]> grant all on . to ‘root’@’192.168.1.%’ identified by ‘hanye131’; Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> flush privileges; Query OK, 0 rows affected (0.01 sec)

再次链接mysql即可

到此,关于“Docker中怎么构建Mariadb”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI