添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

废话不多说,直接进入正题。

下面是我操作的步骤(root账号操作),及遇到的问题和解决办法:

拉取mysql最新镜像,运行容器并制定挂在路径,设置root初始密码(没有用的,但是不影响执行)

docker run --name=mysql -p 3306:3306 -v /home/mysql/var/run/mysqld:/var/run/mysqld -v /home/mysql/var/lib/mysql:/var/lib/mysql -v /home/mysql/etc/mysql:/etc/mysql -v /home/mysql/var/lib/mysql-files:/var/lib/mysql-files/ --privileged=true  -e MYSQL_ROOT_PASSWORD=123456  -d mysql:latest
[ERROR] [MY-010273] [Server] Could not create unix socket lock file /var/run/mysqld/mysqld.sock.lock.

容器不能启动报错。用docker logs –f a40848c0ac06 查看日志发现错误

Initializing database
2019-06-26T03:02:31.827828Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.16) initializing of server in progress as process 27
2019-06-26T03:02:33.775142Z 5 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
2019-06-26T03:02:34.527527Z 0 [System] [MY-013170] [Server] /usr/sbin/mysqld (mysqld 8.0.16) initializing of server has completed
Database initialized
MySQL init process in progress...
MySQL init process in progress...
2019-06-26T03:02:35.988648Z 0 [Warning] [MY-010101] [Server] Insecure configuration for --secure-file-priv: Location is accessible to all OS users. Consider choosing a different directory.
2019-06-26T03:02:35.988690Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.16) starting as process 78
2019-06-26T03:02:36.991298Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2019-06-26T03:02:36.991588Z 0 [ERROR] [MY-010273] [Server] Could not create unix socket lock file /var/run/mysqld/mysqld.sock.lock.
2019-06-26T03:02:36.991597Z 0 [ERROR] [MY-010268] [Server] Unable to setup unix socket lock file.
MySQL init process in progress...
MySQL init process in progress...
2019-06-26T03:02:36.991778Z 0 [ERROR] [MY-010119] [Server] Aborting
2019-06-26T03:02:39.086053Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.16)  MySQL Community Server - GPL.
MySQL init process in progress...
MySQL init process in progress...
MySQL init process in progress...
MySQL init process in progress...
MySQL init process in progress...
MySQL init process in progress...
MySQL init process in progress...
MySQL init process in progress...
MySQL init process in progress...
MySQL init process in progress...
MySQL init process in progress...
MySQL init process in progress...
MySQL init process in progress...
MySQL init process in progress...
MySQL init process in progress...
MySQL init process in progress...
MySQL init process in progress...
MySQL init process in progress...
MySQL init process in progress...
MySQL init process in progress...
MySQL init process in progress...
MySQL init process in progress...
MySQL init process in progress...
MySQL init process in progress...
MySQL init process in progress...
MySQL init process in progress...
MySQL init process in progress...
MySQL init process failed.
2019-06-26T03:10:02.580247Z 0 [Warning] [MY-010101] [Server] Insecure configuration for --secure-file-priv: Location is accessible to all OS users. Consider choosing a different directory.
2019-06-26T03:10:02.580288Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.16) starting as process 1
2019-06-26T03:10:02.983867Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2019-06-26T03:10:02.993561Z 0 [ERROR] [MY-010273] [Server] Could not create unix socket lock file /var/run/mysqld/mysqld.sock.lock.
2019-06-26T03:10:02.993582Z 0 [ERROR] [MY-010268] [Server] Unable to setup unix socket lock file.
2019-06-26T03:10:02.994647Z 0 [ERROR] [MY-010119] [Server] Aborting

这个是因为容器启动的时候,挂载到宿主机的目录权限有问题。需要修改

解决办法:

chown -R polkitd:input /home/mysql

然后就是挂载出来,mysql配置文件丢失。使用起来很不方便。

解决办法:将容器中的mysql配置文件copy出来,然后再重启。具体操作如下:

1、创建容器的时候,可以挂在一个容器中空目录比如 /mysql/conf

2、容器起来以后,docker exec -it 28b941608555 /bin/bash 进入容器,创建目录/mysql/conf,然后将/etc/mysql中的配置文件拷贝到/mysql/conf中,然后宿主机中对应的目录就有配置文件了cp /etc/mysql/* /mysql/conf –r

3、最后将现在的容器删掉,重新对应挂载-v /opt/mysql/etc/mysql:/etc/mysql 创建新容器。

4、这样就可以通过宿主机中的配置,来改变docker容器中的mysql服务。

[root@localhost home]# mysql -uroot -p123456

发现没有mysql命令,这是因为没有mysql客户端

解决办法: yum install -y mariadb.x86_64 mariadb-libs.x86_64

[root@localhost home]# mysql -uroot -p123456

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

解决办法:ln -s /home/mysql/var/run/mysqld/mysqld.sock /var/lib/mysql/mysql.sock

 [root@localhost home]# mysql -h10.10.2.53 -uroot -p123456

ERROR 2003 (HY000): Can't connect to MySQL server on '10.10.2.53' (111)

说明:不能远程访问访问

[root@localhost mysqld]# mysql -uroot -p123456

ERROR 2059 (HY000): Authentication plugin 'caching_sha2_password' cannot be loaded: /usr/lib64/mysql/plugin/caching_sha2_password.so: cannot open shared object file: No such file or directory

说明:远程访问,密码加密方式不对,需要使用caching_sha2_password来处理(现在的客户端应该使用的是mysql_native_password)

分析原因:综合起来是用户的问题、密码加密的问题。

最初的用户权限表是这样的:(SELECT `Host`, `User`, `plugin`, authentication_string, password_expired FROM `user`)

从这个表可以看出,root用户是不能远程访问的。可以本地访问,不需要密码。

解决办法:

本地登录mysql服务,增加root远程登录,并且使用mysql_native_password加密方式

要实现本地登录容器中运行的mysql服务,有两种方式

方式1:docker exec –it a40848c0ac06 bash 进入容器后,mysql -uroot –p 不需要输入密码

方式2:docker exec –it a40848c0ac06 mysql -uroot –p 不需要输入密码

然后增加root远程登录,并且使用mysql_native_password加密方式

create USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';

flush privileges;

到此出就好了。

有些容器会自动产生一些数据,为了不让数据随着container的消失而消失,保证数据的安全性。例如:数据库容器,数据表的表会产生一些数据,如果我把container给删除,数据就丢失。为了保证数据不丢失,这就有了Volume的存在。Volume 是保存Docker容器生成和使用的数据的首选机制。虽然bind mounts依赖于主机的目录结构,但Volume完全由Docker管理。Volume绑... 原文标题:Docker Basics: How to Share Data Between a Docker Container and Host,作者:Jack Wallen有了Docker容器,贵公司可以大规模、迅速地提供应用程序和服务。又由于部署容器化应用程序如此简单,你可以很快上手。你在接触Docker后可能很快发现一点,一旦部署完毕,容器在如何保存和包含数据方面很有限,而这种限... 深知大多数初级Java工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则近万的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!因此收集整理了一份《Java开发全套学习资料》送给大家,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。 如上图,可以看到,该系统是通过docker-compose.yml文件将宿主机(dev00)上的db目录挂载到了mysql:5.7.24容器对应的/var/lib/mysql目录下,但是通过ls命令可以看到,该db目录在宿主机上的用户及用户组为polkitd:input,这个时候会很奇怪,并没有建立这俩用户,也没赋权限,为何他的用 Docker官方的MySQL镜像的Dockerfile托管在Github上,地址如下:https://github.com/docker-library/mysql/tree/5836bc9af9deb67b68c32bebad09a0f7513da36e/5.6仔细研究了一下其Dockerfile,发现最有技术含量的倒不是其Dockerfile本身,无非是更新软件仓库,下载Mysql Serve...