1.第一种:mysql -uroot -p ‘bai123’(直接用密码连接)
[root@bai mysql]# mysql -uroot -p'bai123'
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.
- 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.
3. mysql -uroot -p123456 -S/tmp/mysql.sock(用socket连接第一种差不多)
```powershell
[root@bai mysql]# mysql -uroot -p'bai123' -S/tmp/mysql.sock
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 14
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.
mysql>
- 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]#
```