gpt4 book ai didi

mysql - 如何在 MySQL CLI 中切换连接?

转载 作者:行者123 更新时间:2023-11-29 15:42:25 24 4
gpt4 key购买 nike

我正在关注本教程 Create MySQL Server Database with Azure 。我成功创建了连接;我的问题是,当我使用 mysql cli 时,我连接到 localhost 连接,而不是 Azure 连接。是否有一个命令可以让我选择要在 cli 中使用的连接?抱歉,如果这太明显了,但我无法找到演示如何做到这一点的来源。如果这是重复的问题,请说明原因并指出同一问题的直接答案,我将删除此问题。谢谢!!

我尝试了命令“\connect azure-XXXX@mysql-azure-XXXX”,但我得到“->”,就像什么都没发生一样,然后输入“status”,仍然显示我的本地主机连接。基本上我有两个活跃的连接。当我关闭本地主机连接并尝试检查事件“azure”连接的状态时,我收到错误“查询期间丢失与 MySQL 服务器的连接”

mysql>状态

86_64 (MySQL Community Server - GPL)

Connection id: 10
Current database:
Current user: root@localhost
SSL: Cipher in use is DHE-RSA-xxxxxxxx
Using delimiter: ;
Server version: 8.0.17 MySQL Community Server - GPL
Protocol version: 10
Connection: localhost via TCP/IP
Server characterset: xxxx
Db characterset: xxxx
Client characterset: xxx
Conn. characterset: xxx
TCP port: 3306
Uptime: 18 hours 17 min 6 sec

Threads: 2 Questions: 11 Slow queries: 0 Opens: 115 Flush tables: 3 Open t
bles: 35 Queries per second avg: 0.000

这就是我想要达到的目标:

Enter password: ***********
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 65512
Server version: 5.6.26.0 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, 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> status
--------------
mysql Ver 14.14 Distrib 5.6.35, for Win64 (x86_64)

Connection id: 65512
Current database:
Current user: myadmin@116.230.243.143
SSL: Not in use
Using delimiter: ;
Server version: 5.6.26.0 MySQL Community Server (GPL)
Protocol version: 10
Connection: mydemoserver.mysql.database.azure.com via TCP/IP
Server characterset: latin1
Db characterset: latin1
Client characterset: gbk
Conn. characterset: gbk
TCP port: 3306
Uptime: 2 days 9 hours 47 min 20 sec

Threads: 4 Questions: 34833 Slow queries: 2 Opens: 84 Flush tables: 4 Open tables: 1 Queries per second avg: 0.167
--------------

mysql>

最佳答案

首先,我认为你应该退出或退出 MySQL:

mysql>quit

更多命令请参见mysql Client Commands .

既然您已经遵循了教程Create MySQL Server Database with Azure .

使用命令重新连接 Azure MySQL:

mysql --host <fully qualified server name> --user <server admin login name>@<server name> -p

例如:

mysql --host mydemoserver.mysql.database.azure.com --user myadmin@mydemoserver -p

连接后,mysql 实用程序会显示 mysql> 提示符,您可以在其中键入命令。

以下是 mysql 输出示例:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 65505
Server version: 5.6.26.0 MySQL Community Server (GPL)

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>

然后请再次运行mysql> status

希望这有帮助。

关于mysql - 如何在 MySQL CLI 中切换连接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57464000/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com