- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我无法从我的主机 (OSX 10.13.6) 连接到在 docker 容器中运行的 mysql 服务器。
如果我在我的主机上启动一个 mysql 服务器(mariadb)(不使用 docker),我可以使用 mysql 客户端成功连接到 mysql 服务器:
~$ mysql.server start
Starting MariaDB
.200805 13:41:03 mysqld_safe Logging to '/usr/local/var/mysql/My-MacBook-Pro-2.local.err'.
200805 13:41:03 mysqld_safe Starting mysqld daemon with databases from /usr/local/var/mysql
SUCCESS!
~$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.5.5-10.4.13-MariaDB Homebrew
Copyright (c) 2000, 2015, 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> use mydb;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select * from people;
+----+--------+------+
| id | name | info |
+----+--------+------+
| 1 | 7stud | abc |
| 2 | Beth | xxx |
| 3 | Diane | xyz |
| 4 | Kathy | xyz |
| 5 | Kathy | xyz |
| 6 | Dave | efg |
| 7 | Tom | zzz |
| 8 | David | abc |
| 9 | Eloise | abc |
| 10 | Jess | xyz |
| 11 | Jeffsy | 2.0 |
| 12 | XXX | xxx |
| 13 | XXX | xxx |
+----+--------+------+
13 rows in set (0.00 sec)
mysql> exit
Bye
~$ mysql.server stop
Shutting down MariaDB
.. SUCCESS!
接下来,如果我在 docker 容器内运行 mysql 服务器,我可以从容器内成功连接到 mysql 服务器:
~$ docker run --rm --name my-mysql -e MYSQL_ROOT_PASSWORD=kathy -p 3606:3606 -d mysql
7457d62496b109fda41b57dea026cc6762bb2b7e754cb3e1987228b55ec461f7
~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7457d62496b1 mysql "docker-entrypoint.s…" 2 seconds ago Up 2 seconds 3306/tcp, 33060/tcp, 0.0.0.0:3606->3606/tcp my-mysql
~$ docker exec -it my-mysql bash
root@7457d62496b1:/# mysql -u root -p
Enter password: kathy
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.21 MySQL Community Server - GPL
Copyright (c) 2000, 2020, 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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.01 sec)
mysql> exit
Bye
root@7457d62496b1:/# exit
exit
~$
但是,如果我尝试从我的主机连接到在 docker 容器中运行的 mysql 服务器,我会失败:
~$ mysql -h 127.0.0.1:3306 -u root -p
Enter password: kathy
ERROR 2005 (HY000): Unknown MySQL server host '127.0.0.1:3306' (0)
~$ docker inspect my-mysql
[
{
"Id": "7457d62496b109fda41b57dea026cc6762bb2b7e754cb3e1987228b55ec461f7",
"Created": "2020-08-05T19:49:32.0561306Z",
"Path": "docker-entrypoint.sh",
"Args": [
"mysqld"
],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 7109,
"ExitCode": 0,
"Error": "",
"StartedAt": "2020-08-05T19:49:32.4423804Z",
"FinishedAt": "0001-01-01T00:00:00Z"
},
"Image": "sha256:0d64f46acfd1af4ee6a162f80c6e07e843761bf14d412060023bf0e69e720fb4",
"ResolvConfPath": "/var/lib/docker/containers/7457d62496b109fda41b57dea026cc6762bb2b7e754cb3e1987228b55ec461f7/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/7457d62496b109fda41b57dea026cc6762bb2b7e754cb3e1987228b55ec461f7/hostname",
"HostsPath": "/var/lib/docker/containers/7457d62496b109fda41b57dea026cc6762bb2b7e754cb3e1987228b55ec461f7/hosts",
"LogPath": "/var/lib/docker/containers/7457d62496b109fda41b57dea026cc6762bb2b7e754cb3e1987228b55ec461f7/7457d62496b109fda41b57dea026cc6762bb2b7e754cb3e1987228b55ec461f7-json.log",
"Name": "/my-mysql",
"RestartCount": 0,
"Driver": "overlay2",
"Platform": "linux",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "",
"ExecIDs": null,
"HostConfig": {
"Binds": null,
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {}
},
"NetworkMode": "default",
"PortBindings": {
"3606/tcp": [
{
"HostIp": "",
"HostPort": "3606"
}
]
},
"RestartPolicy": {
"Name": "no",
"MaximumRetryCount": 0
},
"AutoRemove": true,
"VolumeDriver": "",
"VolumesFrom": null,
"CapAdd": null,
"CapDrop": null,
"Capabilities": null,
"Dns": [],
"DnsOptions": [],
"DnsSearch": [],
"ExtraHosts": null,
"GroupAdd": null,
"IpcMode": "private",
"Cgroup": "",
"Links": null,
"OomScoreAdj": 0,
"PidMode": "",
"Privileged": false,
"PublishAllPorts": false,
"ReadonlyRootfs": false,
"SecurityOpt": null,
"UTSMode": "",
"UsernsMode": "",
"ShmSize": 67108864,
"Runtime": "runc",
"ConsoleSize": [
0,
0
],
"Isolation": "",
"CpuShares": 0,
"Memory": 0,
"NanoCpus": 0,
"CgroupParent": "",
"BlkioWeight": 0,
"BlkioWeightDevice": [],
"BlkioDeviceReadBps": null,
"BlkioDeviceWriteBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteIOps": null,
"CpuPeriod": 0,
"CpuQuota": 0,
"CpuRealtimePeriod": 0,
"CpuRealtimeRuntime": 0,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": [],
"DeviceCgroupRules": null,
"DeviceRequests": null,
"KernelMemory": 0,
"KernelMemoryTCP": 0,
"MemoryReservation": 0,
"MemorySwap": 0,
"MemorySwappiness": null,
"OomKillDisable": false,
"PidsLimit": null,
"Ulimits": null,
"CpuCount": 0,
"CpuPercent": 0,
"IOMaximumIOps": 0,
"IOMaximumBandwidth": 0,
"MaskedPaths": [
"/proc/asound",
"/proc/acpi",
"/proc/kcore",
"/proc/keys",
"/proc/latency_stats",
"/proc/timer_list",
"/proc/timer_stats",
"/proc/sched_debug",
"/proc/scsi",
"/sys/firmware"
],
"ReadonlyPaths": [
"/proc/bus",
"/proc/fs",
"/proc/irq",
"/proc/sys",
"/proc/sysrq-trigger"
]
},
"GraphDriver": {
"Data": {
"LowerDir": "/var/lib/docker/overlay2/bd8cf726bca86b4a5da2253ba4d8fd809e7888bd0a8585337e365f00d4ce0a3c-init/diff:/var/lib/docker/overlay2/d28436ec5b86d97829d4db76ecac79feedf9d7de78be7fac9364b9030e5501c6/diff:/var/lib/docker/overlay2/b4ccb4e64dccd4466971f59b4ddefc0d69943e8a0bb6327dbeccd602d2550378/diff:/var/lib/docker/overlay2/b033c732901687d589a6bd69df8249f661fc9221b8305b32084dfd506dd6014f/diff:/var/lib/docker/overlay2/7078174167da7480c3bea6bf1bb831c1de53479e6c866ac88634ba83560c702e/diff:/var/lib/docker/overlay2/413086cc620e9c9a9bfab7fccaa0cb7e5836419ad52453ae76accf6c9f09be8d/diff:/var/lib/docker/overlay2/0a2c718ad2009d757554e539995cf5901bca5cd1a5ffb9d430ee137fb843adc8/diff:/var/lib/docker/overlay2/00e175c2a0975b7663ccadde84d5bd2f8ea957e9e302ab5c20a9840e34ddd0c5/diff:/var/lib/docker/overlay2/7be82f60f3b9fcb23d0d6336005987dd2c98667622833b58fa9f6362a2a02ba5/diff:/var/lib/docker/overlay2/8c347ec6ae30e0109728c0a056d36b5c64b8f907ec482dc9680bc2d8cfe6e9ad/diff:/var/lib/docker/overlay2/aaf2ed3d56a5312f4daf6efe6f456d95e54cda92e4efe972862c43489d891d3d/diff:/var/lib/docker/overlay2/88bacf56afbf61f9f8c94037a48df63c9fd549682ecf2c446a705ae661f6fe51/diff:/var/lib/docker/overlay2/3b9cf88d35e75201fd69adf020d396d079f7a513b64bd799c118459fe13446af/diff",
"MergedDir": "/var/lib/docker/overlay2/bd8cf726bca86b4a5da2253ba4d8fd809e7888bd0a8585337e365f00d4ce0a3c/merged",
"UpperDir": "/var/lib/docker/overlay2/bd8cf726bca86b4a5da2253ba4d8fd809e7888bd0a8585337e365f00d4ce0a3c/diff",
"WorkDir": "/var/lib/docker/overlay2/bd8cf726bca86b4a5da2253ba4d8fd809e7888bd0a8585337e365f00d4ce0a3c/work"
},
"Name": "overlay2"
},
"Mounts": [
{
"Type": "volume",
"Name": "f11c80d7d01140465818fac7d5f7e6083ff509abe8591166a20caa1f568c7646",
"Source": "/var/lib/docker/volumes/f11c80d7d01140465818fac7d5f7e6083ff509abe8591166a20caa1f568c7646/_data",
"Destination": "/var/lib/mysql",
"Driver": "local",
"Mode": "",
"RW": true,
"Propagation": ""
}
],
"Config": {
"Hostname": "7457d62496b1",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"3306/tcp": {},
"33060/tcp": {},
"3606/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"MYSQL_ROOT_PASSWORD=kathy",
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"GOSU_VERSION=1.12",
"MYSQL_MAJOR=8.0",
"MYSQL_VERSION=8.0.21-1debian10"
],
"Cmd": [
"mysqld"
],
"Image": "mysql",
"Volumes": {
"/var/lib/mysql": {}
},
"WorkingDir": "",
"Entrypoint": [
"docker-entrypoint.sh"
],
"OnBuild": null,
"Labels": {}
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "d7ae1d7c552ff3bd8e3b457646a314cddad73082d463ccca4c8d67a4c77aa574",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"3306/tcp": null,
"33060/tcp": null,
"3606/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "3606"
}
]
},
"SandboxKey": "/var/run/docker/netns/d7ae1d7c552f",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "a642243a0c85b09821ab0bb4e42d310e02a8c29e4b6949212776938c37d23019",
"Gateway": "172.17.0.1",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"MacAddress": "02:42:ac:11:00:02",
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "ce024a8603c56f96f22700049e12c7687e804c4f1aa00638ed9156ddab36b152",
"EndpointID": "a642243a0c85b09821ab0bb4e42d310e02a8c29e4b6949212776938c37d23019",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:11:00:02",
"DriverOpts": null
}
}
}
}
]
~$ mysql -h 172.17.0.2:3306 -u root -p
Enter password: kathy
ERROR 2005 (HY000): Unknown MySQL server host '172.17.0.2:3306' (0)
~$ mysql -h localhost -P 3306 --protocol=tcp -u root -p
Enter password: kathy
ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (61)
~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7457d62496b1 mysql "docker-entrypoint.s…" 10 minutes ago Up 10 minutes 3306/tcp, 33060/tcp, 0.0.0.0:3606->3606/tcp my-mysql
我做错了什么?
尝试 Neo Anderson 的建议:
~$ docker run --rm --name my-mysql -e MYSQL_ROOT_PASSWORD=kathy -p 3306:3306 -d mysql
4cba45a3d758f53256fe88aa9e33ea709a23d0c55c035d4009bbc5685d2e09ee
~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4cba45a3d758 mysql "docker-entrypoint.s…" 4 seconds ago Up 4 seconds 0.0.0.0:3306->3306/tcp, 33060/tcp my-mysql
~$ mysql --host=127.0.0.1 -P 3306 --user=root -p
Enter password: kathy
ERROR 2026 (HY000): SSL connection error: unknown error number
我没有安装 docker-machine,所以我安装了它,但我得到:
~$ docker-machine ip default
Docker machine "default" does not exist. Use "docker-machine ls" to list machines. Use "docker-machine create" to add a new one.
~$ docker-machine ls
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
..
好的,知道了! SSL 连接错误
的原因:
mysql8 can not be accessed by mysql clients lower then version 8
在我的主机上,我有 mysql 版本:
~$ mysql --version
mysql Ver 14.14 Distrib 5.7.10, for osx10.9 (x86_64) using EditLine wrapper
我正在使用 mysql 5.7.10 附带的 mysql 客户端尝试连接到在 docker 容器中运行的 mysql 服务器。但是,docker容器中运行的镜像是mysql:latest
,mysql的最新版本是8.x
。为了解决所有问题,我改用了 docker 镜像 mysql:5.7
:
~$ docker run --rm --name my-mysql -e MYSQL_ROOT_PASSWORD=kathy -p 56789:3306 -d mysql:5.7
94dfc72013bec3fada45225153974173a816ffc4b8a424eea735d57fecf50c4c
现在我可以使用我主机上的 mysql 5.7 客户端
从我的主机连接到在 docker 容器中运行的 mysql 服务器:
~$ mysql -P 56789 -u root -p
Enter password: kathy
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
错误是由于 tcp
不是默认协议(protocol),因此您可以将 localhost 指定为 -h 127.0.0.1
,这会隐式设置协议(protocol)为 tcp,或者您可以使用 --protocol=tcp
显式设置协议(protocol):
~$ mysql -h 127.0.0.1 -P 56789 -u root -p
Enter password: kathy
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.31 MySQL Community Server (GPL)
Copyright (c) 2000, 2015, 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>
或:
~$ mysql -P 56789 --protocol=tcp -u root -p
Enter password: kathy
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.31 MySQL Community Server (GPL)
Copyright (c) 2000, 2015, 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>
最佳答案
默认情况下,mysql
图像在端口 3306 上监听。
在您的 docker run 命令中,您使用的是 -p 3606:3606
。这会创建一个从主机 3606 到同一端口上的容器的 DNAT 规则 - 没有服务正在监听。
尝试使用此命令启动容器(请注意,源可以是您主机上未使用的任何端口 - 在下面的示例中,我保留了您的初始端口 3606):
docker run --rm --name my-mysql -e MYSQL_ROOT_PASSWORD=kathy -p 3606:3306 -d mysql
要将 mysql 客户端从主机连接到容器,请添加 -P
(端口)并明确指定您不使用默认端口:
mysql --host=127.0.0.1 -P 3606 --user=root -p
如果这仍然不起作用,请在您的 Mac 上运行 docker-machine ip default
并将 127.0.0.1 替换为该 IP 地址。
关于mysql - 如何从我的主机连接到在 docker 容器中运行的 mysql 服务器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63272789/
我知道这个问题可能已经被问过,但我检查了所有这些,我认为我的情况有所不同(请友善)。所以我有两个数据集,第一个是测试数据集,第二个是我保存在数据框中的预测(预测值,这就是没有数据列的原因)。我想合并两
在 .loc 方法的帮助下,我根据同一数据框中另一列中的值来识别 Panda 数据框中某一列中的值。 下面给出了代码片段供您引用: var1 = output_df['Player'].loc[out
当我在 Windows 中使用 WinSCP 通过 Ubuntu 连接到 VMware 时,它提示: The server rejected SFTP connection, but it lis
我正在开发一个使用 xml web 服务的 android 应用程序。在 wi-fi 网络中连接时工作正常,但在 3G 网络中连接时失败(未找到 http 404)。 这不仅仅发生在设备中。为了进行测
我有一个XIB包含我的控件的文件,加载到 Interface Builder(Snow Leopard 上的 Xcode 4.0.2)中。 文件的所有者被设置为 someClassController
我在本地计算机上管理 MySQL 数据库,并通过运行以下程序通过 C 连接到它: #include #include #include int main(int argc, char** arg
我不知道为什么每次有人访问我网站上的页面时,都会打开一个与数据库的新连接。最终我到达了大约 300 并收到错误并且页面不再加载。我认为它应该工作的方式是,我将 maxIdle 设置为 30,这意味着
希望清理 NMEA GPS 中的 .txt 文件。我当前的代码如下。 deletes = ['$GPGGA', '$GPGSA', '$GPGSV', '$PSRF156', ] searchquer
我有一个 URL、一个用户名和一个密码。我想在 C# .Net WinForms 中建立 VPN 连接。 你能告诉我从哪里开始吗?任何第三方 API? 代码示例将受到高度赞赏... 最佳答案 您可以像
有没有更好的方法将字符串 vector 转换为字符 vector ,字符串之间的终止符为零。 因此,如果我有一个包含以下字符串的 vector "test","my","string",那么我想接收一
我正在编写一个库,它不断检查 android 设备的连接,并在设备连接、断开连接或互联网连接变慢时给出回调。 https://github.com/muddassir235/connection_ch
我的操作系统:Centos 7 + CLOUDLINUX 7.7当我尝试从服务器登录Mysql时 [root@server3 ~]# Mysql -u root -h localhost -P 330
我收到错误:Puma 发现此错误:无法打开到本地主机的 TCP 连接:9200(连接被拒绝 - 连接(2)用于“本地主机”端口 9200)(Faraday::ConnectionFailed)在我的
请给我一些解决以下错误的方法。 这是一个聊天应用....代码和错误如下:: conversations_controller.rb def create if Conversation.bet
我想将两个单元格中的数据连接到一个单元格中。我还想只组合那些具有相同 ID 的单元格。 任务 ID 名称 4355.2 参与者 4355.2 领袖 4462.1 在线 4462.1 快速 4597.1
我经常需要连接 TSQL 中的字段... 使用“+”运算符时 TSQL 强制您处理的两个问题是 Data Type Precedence和 NULL 值。 使用数据类型优先级,问题是转换错误。 1)
有没有在 iPad 或 iPhone 应用程序中使用 Facebook 连接。 这个想法是登录这个应用程序,然后能够看到我的哪些 facebook 用户也在使用该应用程序及其功能。 最佳答案 是的。
我在连接或打印字符串时遇到了一个奇怪的问题。我有一个 char * ,可以将其设置为字符串文字的几个值之一。 char *myStrLiteral = NULL; ... if(blah) myS
对于以下数据 - let $x := "Yahooooo !!!! Select one number - " let $y := 1 2 3 4 5 6 7 我想得到
我正在看 UDEMY for perl 的培训视频,但是视频不清晰,看起来有错误。 培训展示了如何使用以下示例连接 2 个字符串: #!usr/bin/perl print $str = "Hi";
我是一名优秀的程序员,十分优秀!