How do I find out my MySQL URL, host, port and username?

前端 未结 10 2129
北恋
北恋 2021-01-29 17:35

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 ne

相关标签:
10条回答
  • 2021-01-29 18:15

    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;
    
    0 讨论(0)
  • 2021-01-29 18:19

    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
    --------------
    
    0 讨论(0)
  • 2021-01-29 18:22

    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.

    0 讨论(0)
  • 2021-01-29 18:27

    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;
    
    0 讨论(0)
  • 2021-01-29 18:27
    default-username = root
    password = you-know-it-better
    url for localhost =  jdbc:mysql://localhost
    default-port = 3306
    
    0 讨论(0)
  • 2021-01-29 18:30

    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%";
    
    0 讨论(0)
提交回复
热议问题