MySQL中的兩種登錄方式詳解
MySQL兩種登錄方式
相信很多小伙伴登錄Mysql的時候,毫不猶豫使用賬號、密碼(即:TCP/IP)方式登錄。
今天和大家分享的是另一種登錄方式:socket方式登錄。
首先,二者的區(qū)別:
- 常規(guī)的賬號密碼登錄也就是TCP/IP方式登錄;
- 而socket其實就是利用mysql.sock作為主機和客戶機在同一臺機器上使用unix domain socket作為通信載體進行通信的,其速度比TCP/IP要快很多。
其次,socket使用場景:
- 當一臺主機上因業(yè)務需要或者其他的設計、規(guī)劃需要安裝了多個mysql時(Mysql安裝路徑和端口不同即可)
- 由于環(huán)境變量中同一時只能配置一個mysql的指向或軟連接
- 如果需要登錄未配置的mysql就可以使用socket方式了
最后,兩種登錄方式的具體操作示例如下:
第一種登錄方式(TCP/IP)
語法:
mysql -h IP地址 -u 用戶 -p 密碼 -P 端口
本機操作-h和-P可以忽略,遠程操作時-h不能忽略,否則無法訪問
[root@iZm5egizeg7ei92a04dhb3Z mysql]# mysql -h127.0.0.1 -uroot -p -P3306 Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 32057 Server version: 5.7.27-log 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>
第二種登錄方式(利用mysql.sock登錄)
語法:
mysql -S mysql.sock路徑
如果不確定mysql.sock文件路徑,可以通過“find / -name mysql.sock"來查找
一般在mysql安裝目錄下:
[root@iZm5egizeg7ei92a04dhb3Z mysql]# find / -name mysql.sock /usr/local/mysql/mysql.sock /opt/zbox/tmp/mysql/mysql.sock [root@iZm5egizeg7ei92a04dhb3Z mysql]# mysql -S /opt/zbox/tmp/mysql/mysql.sock Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1063 Server version: 5.5.5-10.5.5-MariaDB Source distribution 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>
總結
以上為個人經驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
MySQL中禁止修改數(shù)據(jù)庫表特定列的實現(xiàn)
本文主要介紹了MySQL數(shù)據(jù)庫中使用觸發(fā)器禁止修改特定列,以保護數(shù)據(jù)的一致性和完整性,下面就來介紹一下,感興趣的可以了解一下2024-12-12
用SELECT... INTO OUTFILE語句導出MySQL數(shù)據(jù)的教程
這篇文章主要介紹了用SELECT... INTO OUTFILE語句導出MySQL數(shù)據(jù)的教程,是MySQL入門學習中的基礎知識,需要的朋友可以參考下2015-05-05
mysql 5.7.18 Installer安裝下載圖文教程
這篇文章主要為大家詳細介紹了mysql 5.7.18 Installer安裝下載圖文教程,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-09-09
Docker部署Mysql數(shù)據(jù)庫的詳細步驟
這篇文章主要介紹了如何使用Docker拉取和部署MySQL鏡像,配置鏡像源,修改容器時區(qū),導入數(shù)據(jù),并通過可視化工具連接和管理數(shù)據(jù)庫,需要的朋友可以參考下2025-03-03
通過DML更新MySQL數(shù)據(jù)庫數(shù)據(jù)的示例代碼
這篇文章主要給大家介紹了如何通過DML更新MySQL數(shù)據(jù)庫的數(shù)據(jù),通過DML來對數(shù)據(jù)庫種地表的數(shù)據(jù)記錄進行增刪改查操作,文中給大家了詳細的代碼示例供大家參考,具有一定的參考價值,需要的朋友可以參考下2024-01-01

