1.第一种:mysql -uroot -p ‘bai123’(直接用密码连接)

    1. [root@bai mysql]# mysql -uroot -p'bai123'
    2. Warning: Using a password on the command line interface can be insecure.
    3. Welcome to the MySQL monitor. Commands end with ; or \g.
    4. Your MySQL connection id is 6
    5. Server version: 5.6.47 MySQL Community Server (GPL)
    6. Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
    7. Oracle is a registered trademark of Oracle Corporation and/or its
    8. affiliates. Other names may be trademarks of their respective
    9. owners.
    10. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    1. mysql -uroot -p123456 -h127.0.0.1 -P3306(一般用于连接别人的) ```powershell [root@bai mysql]# mysql -uroot -p’bai123’-h127.0.0.1 -p3306 Warning: Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 6 Server version: 5.6.47 MySQL Community Server (GPL)

    Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

    Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.

    Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

    1. 3. mysql -uroot -p123456 -S/tmp/mysql.sock(用socket连接第一种差不多)
    2. ```powershell
    3. [root@bai mysql]# mysql -uroot -p'bai123' -S/tmp/mysql.sock
    4. Warning: Using a password on the command line interface can be insecure.
    5. Welcome to the MySQL monitor. Commands end with ; or \g.
    6. Your MySQL connection id is 14
    7. Server version: 5.6.47 MySQL Community Server (GPL)
    8. Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
    9. Oracle is a registered trademark of Oracle Corporation and/or its
    10. affiliates. Other names may be trademarks of their respective
    11. owners.
    12. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    13. mysql>
    1. mysql -uroot -p123456 -e “show databases”(可以直接获取一个数据,在以后脚本会常用) ```powershell [root@bai mysql]# mysql -uroot -p’bai123’ -e ‘show databases’ Warning: Using a password on the command line interface can be insecure. +——————————+ | Database | +——————————+ | information_schema | | mysql | | performance_schema | | test | | ytl | +——————————+ [root@bai mysql]#

    ```