在我的本地计算机上,我可以使用mysql cli命令轻松地连接到mysql数据库的远程实例(假设设置了环境变量):
# mysql -u root -p$DB_PASSWORD -h $DB_HOST --port=$DB_PORT
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7365
Server version: 5.7.14-google (Google)
Copyright (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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
3 rows in set (0.05 sec)
然而,使用docker它就会挂起:
docker run --rm -it --name mysql -e MYSQL_RANDOM_ROOT_PASSWORD=yes mysql \
mysql -u root -p$DB_PASSWORD -h $DB_HOST --port=$DB_PORT
mysql: [Warning] Using a password on the command line interface can be insecure.
show databases;
^C
^C
exit
exit
^C
并且必须从另一个终端窗口执行docker container stop mysql
才能退出mysql容器。
我甚至尝试附加到容器并运行相同的命令,但都无济于事。尝试连接到AWS MySQL实例和Google Cloud SQL实例,还尝试直接在命令行中输入变量,结果都相同。为什么它会挂起来,我怎么才能让它工作呢?谢谢!
发布于 2018-06-19 06:59:18
我使用的是Google Cloud SQL,需要将IP地址列入白名单才能允许访问。因此,添加这些解决了连接问题。
发布于 2018-06-15 08:30:34
尝试公开MySQL的默认端口
docker run -p 3306:3306 ...
发布于 2019-12-26 18:49:34
我尝试了所有的方法,但下面的步骤已经解决了我的问题。在容器内运行命令
dpkg-重新配置tzdata
它将要求您选择地理区域和时区,然后您就完成了。
https://stackoverflow.com/questions/50864802
复制相似问题