• 本地登录多实例mysql ,默认登录数据库问题


    本地登录多实例mysql ,默认登录数据库问题

    本地多实例mysql 环境,有 3306和3307 两个端口的实例。

    当本地登录时,以下登录方式登录进去的都是 3306 实例
    [root@testdb1 ~]# mysql -uroot -pchengce243 -P3306 -e "show variables like 'port';"
    mysql: [Warning] Using a password on the command line interface can be insecure.
    +---------------+-------+
    | Variable_name | Value |
    +---------------+-------+
    | port | 3306 |
    +---------------+-------+

    [root@testdb1 ~]# mysql -uroot -pchengce243 -P3307 -e "show variables like 'port';"
    mysql: [Warning] Using a password on the command line interface can be insecure.
    +---------------+-------+
    | Variable_name | Value |
    +---------------+-------+
    | port | 3306 |
    +---------------+-------+

    甚至一个不存在的端口号 9088 登录进去的依然是 3306 实例
    [root@testdb1 ~]# mysql -uroot -pchengce243 -P9088 -e "show variables like 'port';"
    mysql: [Warning] Using a password on the command line interface can be insecure.
    +---------------+-------+
    | Variable_name | Value |
    +---------------+-------+
    | port | 3306 |
    +---------------+-------+


    要想登录到指定的端口号,必须指定 -h 参数 。
    [root@testdb1 ~]# mysql -uroot -pchengce243 -h127.0.0.1 -P3306 -e "show variables like 'port';"
    mysql: [Warning] Using a password on the command line interface can be insecure.
    +---------------+-------+
    | Variable_name | Value |
    +---------------+-------+
    | port | 3306 |
    +---------------+-------+

    [root@testdb1 ~]# mysql -uroot -pchengce243 -h127.0.0.1 -P3307 -e "show variables like 'port';"
    mysql: [Warning] Using a password on the command line interface can be insecure.
    +---------------+-------+
    | Variable_name | Value |
    +---------------+-------+
    | port | 3307 |
    +---------------+-------+

    原因:如果不指定 -h 参数,只指定 -P 参数,默认就会去读取 默认的配置文件 中的 [client] 部分,也就是 /etc/my.cnf
    查看 /etc/my.cnf 得知,配置的端口号就是 3306,以下验证一下结论,修改 /etc/my.cnf port 参数为 4406

    [root@testdb1 ~]# mysql -uroot -pchengce243 -P3307 -e "show variables like 'port';"
    mysql: [Warning] Using a password on the command line interface can be insecure.
    +---------------+-------+
    | Variable_name | Value |
    +---------------+-------+
    | port | 4406 |
    +---------------+-------+
    [root@testdb1 ~]# mysql -uroot -pchengce243 -P3306 -e "show variables like 'port';"
    mysql: [Warning] Using a password on the command line interface can be insecure.
    +---------------+-------+
    | Variable_name | Value |
    +---------------+-------+
    | port | 4406 |
    +---------------+-------+
    [root@testdb1 ~]# mysql -uroot -pchengce243 -P9306 -e "show variables like 'port';"
    mysql: [Warning] Using a password on the command line interface can be insecure.
    +---------------+-------+
    | Variable_name | Value |
    +---------------+-------+
    | port | 4406 |
    +---------------+-------+

    可以看到上面系统中并不存在的 3306端口和 9306 端口,登录进去就是修改后的 4406 端口。

    [root@testdb1 ~]# mysql -uroot -pchengce243 -h127.0.0.1 -P4406 -e "show variables like 'port';"
    mysql: [Warning] Using a password on the command line interface can be insecure.
    +---------------+-------+
    | Variable_name | Value |
    +---------------+-------+
    | port | 4406 |
    +---------------+-------+

    [root@testdb1 ~]# mysql -uroot -pchengce243 -h127.0.0.1 -P3307 -e "show variables like 'port';"
    mysql: [Warning] Using a password on the command line interface can be insecure.
    +---------------+-------+
    | Variable_name | Value |
    +---------------+-------+
    | port | 3307 |
    +---------------+-------+

    [root@testdb1 ~]# mysql -uroot -pchengce243 -h127.0.0.1 -P3306 -e "show variables like 'port';"
    mysql: [Warning] Using a password on the command line interface can be insecure.
    ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111)
    [root@testdb1 ~]# mysql -uroot -pchengce243 -h127.0.0.1 -P9306 -e "show variables like 'port';"
    mysql: [Warning] Using a password on the command line interface can be insecure.
    ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111)


    所以为了解决本地登录时端口乱串的问题,最好指定 -h 参数,就不会发生登录到默认数据库的问题了。

  • 相关阅读:
    U盘为什么还有剩余空间,但却提示说空间不够
    U盘安装系统
    win8 64位+Oracle 11g 64位下使用PL/SQL Developer 的解决办法
    Oracle 去掉重复字符串
    ORACLE获取字符串中数字部分
    MyBatis中的大于、小于、like等符号写法
    Oracle计算时间差函数
    HDU 3569 Imaginary Date 简单期望
    C语言之——文件操作模式
    LeetCode OJ 之 Ugly Number II (丑数-二)
  • 原文地址:https://www.cnblogs.com/liang545621/p/12704249.html
Copyright © 2020-2023  润新知