如何找到我的 MySQL URL、主机、端口和用户名?

发布于 2024-09-30 21:55:39 字数 104 浏览 0 评论 0原文

我需要找到我的 MySQL 用户名。当我打开 MySQL 命令行客户端时,它只询问我的密码。我不记得我的用户名了。为了与 JDBC 连接,我需要 URL、主机和端口号。我在哪里可以找到所有这些?

I need to find my MySQL username. When I open the MySQL command line client, it only asks me for my password. I don't remember my username. And for connectivity with JDBC, I need the URL, host and port number. Where do I find all of these?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(12

罗罗贝儿 2024-10-07 21:55:39

如果您已经登录到命令行客户端,请尝试以下操作:

mysql> select user();

它将输出类似于以下内容的内容:

+----------------+
| user()         |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.41 sec)

在上面的示例中,我从 localhostroot 身份登录。

要查找端口号和其他有趣的设置,请使用以下命令:

mysql> show variables;

If you're already logged into the command line client try this:

mysql> select user();

It will output something similar to this:

+----------------+
| user()         |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.41 sec)

In my example above, I was logged in as root from localhost.

To find port number and other interesting settings use this command:

mysql> show variables;
貪欢 2024-10-07 21:55:39

如果您想知道运行 Mysql 的本地主机的端口号,您可以在 MySQL 命令行客户端上使用此查询 -

SHOW VARIABLES WHERE Variable_name = 'port';


mysql> SHOW VARIABLES WHERE Variable_name = 'port';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port          | 3306  |
+---------------+-------+
1 row in set (0.00 sec)

它将为您提供 MySQL 运行的端口号。


如果您想知道 Mysql 的主机名,您可以在 MySQL 命令行客户端上使用此查询 -

SHOW VARIABLES WHERE Variable_name = 'hostname';


mysql> SHOW VARIABLES WHERE Variable_name = 'hostname';
+-------------------+-------+
| Variable_name     | Value |
+-------------------+-------+
| hostname          | Dell  |
+-------------------+-------+
1 row in set (0.00 sec)

它将为您提供 mysql 的主机名。


如果您想知道 Mysql 的用户名,您可以在 MySQL 命令行客户端上使用此查询 -

select user();   


mysql> select user();
+----------------+
| user()         |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.00 sec)

它将为您提供 mysql 的用户名。

If you want to know the port number of your local host on which Mysql is running you can use this query on MySQL Command line client --

SHOW VARIABLES WHERE Variable_name = 'port';


mysql> SHOW VARIABLES WHERE Variable_name = 'port';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port          | 3306  |
+---------------+-------+
1 row in set (0.00 sec)

It will give you the port number on which MySQL is running.


If you want to know the hostname of your Mysql you can use this query on MySQL Command line client --

SHOW VARIABLES WHERE Variable_name = 'hostname';


mysql> SHOW VARIABLES WHERE Variable_name = 'hostname';
+-------------------+-------+
| Variable_name     | Value |
+-------------------+-------+
| hostname          | Dell  |
+-------------------+-------+
1 row in set (0.00 sec)

It will give you the hostname for mysql.


If you want to know the username of your Mysql you can use this query on MySQL Command line client --

select user();   


mysql> select user();
+----------------+
| user()         |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.00 sec)

It will give you the username for mysql.

帅冕 2024-10-07 21:55:39

例如,您可以尝试:

//If you want to get user, you need start query in your mysql:
SELECT user(); // output your user: root@localhost
SELECT system_user(); // --

//If you want to get port your "mysql://user:pass@hostname:port/db"
SELECT @@port; //3306 is default

//If you want hostname your db, you can execute query
SELECT @@hostname;

For example, you can try:

//If you want to get user, you need start query in your mysql:
SELECT user(); // output your user: root@localhost
SELECT system_user(); // --

//If you want to get port your "mysql://user:pass@hostname:port/db"
SELECT @@port; //3306 is default

//If you want hostname your db, you can execute query
SELECT @@hostname;
苦妄 2024-10-07 21:55:39

如果您不知道确切的变量名称,请使用 like,因为结果可能包含超过 500 行:

mysql> show variables like "%port%";

If you don't know the exact variable name use like, as the result may contain more than 500 rows:

mysql> show variables like "%port%";
瘫痪情歌 2024-10-07 21:55:39

如果使用 MySQL Workbench,只需查看侧边栏信息窗格中的会话选项卡即可。

输入图像描述这里

If using MySQL Workbench, simply look in the Session tab in the Information pane located in the sidebar.

enter image description here

擦肩而过的背影 2024-10-07 21:55:39
default-username = root
password = you-know-it-better
url for localhost =  jdbc:mysql://localhost
default-port = 3306
default-username = root
password = you-know-it-better
url for localhost =  jdbc:mysql://localhost
default-port = 3306
枯寂 2024-10-07 21:55:39

最简单的方法可能是使用命令 status; 在输出中,您将找到数据库、用户、主机和端口:

mysql> status;
--------------
mysql  Ver 8.0.13 for Win64 on x86_64 (MySQL Community Server - GPL)

Connection id:          43
Current database:       mysql
Current user:           user@localhost
SSL:                    Cipher in use is DHE-RSA-AES128-GCM-SHA256
Using delimiter:        ;
Server version:         8.0.13 MySQL Community Server - GPL
Protocol version:       10
Connection:             localhost via TCP/IP
Server characterset:    utf8mb4
Db     characterset:    utf8mb4
Client characterset:    cp852
Conn.  characterset:    cp852
TCP port:               3306
Uptime:                 3 hours 32 min 40 sec

Threads: 3  Questions: 197  Slow queries: 0  Opens: 214  Flush tables: 2  Open tables: 190  Queries per second avg: 0.015
--------------

Easiest way is probably using command status; In the output you'll find database, user, host and port:

mysql> status;
--------------
mysql  Ver 8.0.13 for Win64 on x86_64 (MySQL Community Server - GPL)

Connection id:          43
Current database:       mysql
Current user:           user@localhost
SSL:                    Cipher in use is DHE-RSA-AES128-GCM-SHA256
Using delimiter:        ;
Server version:         8.0.13 MySQL Community Server - GPL
Protocol version:       10
Connection:             localhost via TCP/IP
Server characterset:    utf8mb4
Db     characterset:    utf8mb4
Client characterset:    cp852
Conn.  characterset:    cp852
TCP port:               3306
Uptime:                 3 hours 32 min 40 sec

Threads: 3  Questions: 197  Slow queries: 0  Opens: 214  Flush tables: 2  Open tables: 190  Queries per second avg: 0.015
--------------
似梦非梦 2024-10-07 21:55:39

如果您使用 phpMyAdmin,请单击Home,然后单击顶部菜单上的Variables。在页面上查找端口 设置。它设置的值是您的 MySQL 服务器正在运行的端口。

If you use phpMyAdmin, click on Home, then Variables on the top menu. Look for the port setting on the page. The value it is set to is the port your MySQL server is running on.

清欢 2024-10-07 21:55:39

这里的默认设置

default-usernameroot
default-password 为 null/空 //没有任何意义
对于 apache,default-urllocalhost127.0.0.1
localhost/phpmyadmin for mysql // 如果您使用的是 xampp/wamp/mamp
默认端口 = 3306

Here are the default settings

default-username is root
default-password is null/empty //mean nothing
default-url is localhost or 127.0.0.1 for apache and
localhost/phpmyadmin for mysql // if you are using xampp/wamp/mamp
default-port = 3306

不如归去 2024-10-07 21:55:39
mysql> SHOW VARIABLES WHERE Variable_name = 'hostname';
+---------------+-----------+
| Variable_name | Value     |
+---------------+-----------+
| hostname      | karola-pc |
+---------------+-----------+
1 row in set (0.00 sec)

例如,在我的例子中: karola-pc 是运行 mysql 的主机名。这是我的本地 PC 主机名。

如果它是远程机器,那么您可以直接 ping 该主机,如果,如果您与该机器位于网络中,您应该能够 ping 该主机。

如果是 UNIX 或 Linux,您可以在终端中运行“hostname”命令来检查主机名。
如果是 Windows,您可以在 MyComputer->; 中看到相同的值右键单击-> Properties ->Computer Name 你可以看到(即系统属性)

希望它能回答你的问题。

mysql> SHOW VARIABLES WHERE Variable_name = 'hostname';
+---------------+-----------+
| Variable_name | Value     |
+---------------+-----------+
| hostname      | karola-pc |
+---------------+-----------+
1 row in set (0.00 sec)

For Example in my case : karola-pc is the host name of the box where my mysql is running. And it my local PC host name.

If it is romote box than you can ping that host directly if, If you are in network with that box you should be able to ping that host.

If it UNIX or Linux you can run "hostname" command in terminal to check the host name.
if it is windows you can see same value in MyComputer-> right click -> properties ->Computer Name you can see ( i.e System Properties)

Hope it will answer your Q.

鸠书 2024-10-07 21:55:39

在本地主机或专用服务器上,转到 phpMyAdmin 内的 config.inc 文件

on local host or dedicated server, go to config.inc file inside phpMyAdmin

枕花眠 2024-10-07 21:55:39

使用这个:

show variables where Variable_name = 'port';

你可以使用命令检查更多变量(必须尝试)

show variables;

use this:

show variables where Variable_name = 'port';

you can check more variables by using the command (must try)

show variables;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文