1.MySQL數(shù)據(jù)庫連接
-
1.1MySQL:是一個典型的c/s結(jié)構(gòu)的軟件應(yīng)用,用服務(wù)端有客戶端,MySQL需要專門的客戶端程序,來連接數(shù)據(jù)庫進行管理和操作的。
2.連接方式
-
2.1socket (本地登錄使用)
[root@db01 ~]# mysql -uroot -p123 -S /tmp/mysql.sock #socket本地登錄方式
mysql: [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.7.26 MySQL Community Server (GPL)
Copyright (c) 2000, 2019, 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>
注意:socket登錄的前提,socket文件位置指定準(zhǔn)確,必須要具備XXX@'localhost'相關(guān)的用戶
-
2.2TCP/IP登錄
[root@db01 ~]# mysql -uzfs -p123456 -h10.0.0.91 -P3306
mysql: [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 15
Server version: 5.7.26 MySQL Community Server (GPL)
Copyright (c) 2000, 2019, 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>
-
2.3通過軟件工具遠(yuǎn)程登錄
-
2.3.1SQLyog遠(yuǎn)程連接
SQLyog遠(yuǎn)程連接 -
2.3.2Navicat for MySQL遠(yuǎn)程連接連接
Navicat遠(yuǎn)程連接 -
2.4MySQL常用參數(shù)介紹
| 參數(shù) | 介紹 |
|---|---|
| -u | 用戶名 |
| -p | 密碼 |
| -S | socket文件目錄 |
| -h | IP地址 |
| -P | 端口號(默認(rèn)3306) |
| -e | 免交互執(zhí)行MySQL里的命令,不用登錄進去 |
| 例 | [root@db01 ~]# mysql -uroot -p123 -e "show databases;" |
| < | 將腳本導(dǎo)入到數(shù)據(jù)庫中 |
| 例 | [root@db01 ~]# mysql -uroot -p123<world.sql |
-
2.5MySQL客戶端內(nèi)置功能
| 參數(shù) | 介紹 |
|---|---|
| help | 打印幫助 |
| /G | 將行轉(zhuǎn)成列顯示 |
| Ctrl+C | 返回新的命令行(終止命令) |
| Ctrl+D,exit,quit | 退出登錄 |
| source | 導(dǎo)入腳本 (source /root/word.sql) |

