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

前端 未结 10 2133
北恋
北恋 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: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.

提交回复
热议问题