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

时间:2021-04-06 07:10:13

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?

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

8 个解决方案

#1


172  

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;

#2


108  

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 --

如果您想知道正在运行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)

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

它会给出MySQL运行的端口号。


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

如果你想知道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)

It will give you the hostname for mysql.

它会给你mysql的主机名。


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

如果你想知道Mysql的用户名,你可以在Mysql命令行客户端使用这个查询—

select user();   


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

It will give you the username for mysql.

它会给你mysql的用户名。

#3


11  

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;

#4


10  

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

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

mysql> show variables like "%port%";

#5


9  

default-username = root
password = you-know-it-better
url for localhost =  jdbc:mysql://localhost
default-port = 3306

#6


2  

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.

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

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.

如果它是romote box,你可以直接ping那个主机,如果你在网络中,你应该能够ping那个主机。

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)

如果是UNIX或Linux,您可以在终端上运行“hostname”命令来检查主机名。如果是windows,你可以在my>中看到相同的值,右键单击->属性->电脑名称(i)。e系统属性)

Hope it will answer your Q.

希望它能回答你的问题。

#7


1  

Here are the default settings

这里是默认设置

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

#8


0  

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.

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

#1


172  

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;

#2


108  

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 --

如果您想知道正在运行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)

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

它会给出MySQL运行的端口号。


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

如果你想知道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)

It will give you the hostname for mysql.

它会给你mysql的主机名。


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

如果你想知道Mysql的用户名,你可以在Mysql命令行客户端使用这个查询—

select user();   


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

It will give you the username for mysql.

它会给你mysql的用户名。

#3


11  

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;

#4


10  

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

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

mysql> show variables like "%port%";

#5


9  

default-username = root
password = you-know-it-better
url for localhost =  jdbc:mysql://localhost
default-port = 3306

#6


2  

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.

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

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.

如果它是romote box,你可以直接ping那个主机,如果你在网络中,你应该能够ping那个主机。

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)

如果是UNIX或Linux,您可以在终端上运行“hostname”命令来检查主机名。如果是windows,你可以在my>中看到相同的值,右键单击->属性->电脑名称(i)。e系统属性)

Hope it will answer your Q.

希望它能回答你的问题。

#7


1  

Here are the default settings

这里是默认设置

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

#8


0  

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.

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