MySQL中的兩種登錄方式詳解
MySQL兩種登錄方式
相信很多小伙伴登錄Mysql的時候,毫不猶豫使用賬號、密碼(即:TCP/IP)方式登錄。
今天和大家分享的是另一種登錄方式:socket方式登錄。
首先,二者的區(qū)別:
- 常規(guī)的賬號密碼登錄也就是TCP/IP方式登錄;
- 而socket其實就是利用mysql.sock作為主機(jī)和客戶機(jī)在同一臺機(jī)器上使用unix domain socket作為通信載體進(jìn)行通信的,其速度比TCP/IP要快很多。
其次,socket使用場景:
- 當(dāng)一臺主機(jī)上因業(yè)務(wù)需要或者其他的設(shè)計、規(guī)劃需要安裝了多個mysql時(Mysql安裝路徑和端口不同即可)
- 由于環(huán)境變量中同一時只能配置一個mysql的指向或軟連接
- 如果需要登錄未配置的mysql就可以使用socket方式了
最后,兩種登錄方式的具體操作示例如下:
第一種登錄方式(TCP/IP)
語法:
mysql -h IP地址 -u 用戶 -p 密碼 -P 端口
本機(jī)操作-h和-P可以忽略,遠(yuǎn)程操作時-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>
總結(jié)
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
MySQL數(shù)據(jù)庫常用操作技巧總結(jié)
這篇文章主要介紹了MySQL數(shù)據(jù)庫常用操作技巧,結(jié)合實例形式總結(jié)分析了mysql查詢、存儲過程、字符串截取、時間、排序等常用操作技巧,需要的朋友可以參考下2018-03-03CentOS7環(huán)境下安裝MySQL5.5數(shù)據(jù)庫
大家好,本篇文章主要講的是CentOS7環(huán)境下安裝MySQL5.5數(shù)據(jù)庫,感興趣的同學(xué)趕快來看一看吧,對你有幫助的話記得收藏一下,方便下次瀏覽2021-12-12數(shù)據(jù)庫性能測試之sysbench工具的安裝與用法詳解
sysbench是一個很不錯的數(shù)據(jù)庫性能測試工具,這篇文章主要給大家介紹了關(guān)于數(shù)據(jù)庫性能測試之sysbench工具的安裝與用法的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2018-07-07MySQL 4G內(nèi)存服務(wù)器配置優(yōu)化
MySQL對于web架構(gòu)性能的影響最大,也是關(guān)鍵的核心部分。下面我們了解一下MySQL優(yōu)化的一些基礎(chǔ),MySQL自身(my.cnf)的優(yōu)化2017-07-07詳解騰訊云CentOS7.0使用yum安裝mysql及使用遇到的問題
本篇文章主要介紹了騰訊云CentOS7.0使用yum安裝mysql,詳細(xì)的介紹了使用yum安裝mysql及使用遇到的問題,有興趣的可以了解一下。2017-01-01