连接 Mysql
远程连接 < 使用 socket 连接 >
[root@dl-001 ~]# mysql -uroot -p'mysqldl991124' -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 2
Server version: 5.6.35 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, 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> quit
Bye
说明:-S:=socket,指定 socket(在配置文件 /etc/my.cnf 文件中即可查看 socket)。此方法只适用于本地连接,等同于“mysql -uroot -p123456”。
本机登录
[root@dl-001 ~]# mysql -uroot -p'mysqldl991124' -h127.0.0.1 -P3306 //-p 指定端口, -h本地ip进行登录
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 3
Server version: 5.6.35 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, 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>
登录的同时执行一条命令
[root@dl-001 ~]# mysql -uroot -p'mysqldl991124' -e 'show databases' //登录并查看所有的库
Warning: Using a password on the command line interface can be insecure.
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+