mysql的登陸方式有兩種,分別是socket和tcp/ip方式登陸。
socket(只能用於本地連線)
當server和client在同一臺伺服器上的時候,我們可以直接用mysql命令登陸。
當什麼引數都沒有指定的時候,mysql預設使用socket方式登陸,如果/etc/my.cnf的[client]沒有指定socket檔案路徑時,mysql缺省會去尋找/tmp/mysql.sock,所以如果mysql服務啟動的時候,生成的socket檔案不是預設路徑的話,登陸會報錯(error 2002 (hy000): can't connect to local mysql server through socket '/tmp/mysql.sock')。[root@localhost ~]# /usr/local/mysql55/bin/mysql
welcome to the mysql monitor. commands end with ; or \g.
your mysql connection id is 3
server version: 5.5.60-log source distribution
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> status
--------------
/usr/local/mysql55/bin/mysql ver 14.14 distrib 5.5.60, for linux (x86_64) using readline 5.1
connection id: 3
current database:
current user: root@localhost
ssl: not in use
current pager: stdout
using outfile: ''
using delimiter: ;
server version: 5.5.60-log source distribution
protocol version: 10
connection: localhost via unix socket
server characterset: utf8
db characterset: utf8
client characterset: utf8
conn. characterset: utf8
unix socket: /tmp/mysql.sock
uptime: 21 hours 40 min 17 sec
[root@localhost ~]# cat /etc/my.cnf.bak
[mysqld]
datadir=/data/mysql
socket=/tmp/mysql.sock
mysql服務啟動的時候,socket檔案的生成目錄可以在[mysqld]上指定,如果沒有指定,預設是/tmp/mysql.sock。
tcp/ip(適合遠端連線,本地也可以使用)
mysql登陸的時候,指定引數-h,會使用tcp/ip的方式連線,如果沒有指定埠的話,預設是使用3306埠
[root@localhost ~]# /usr/local/mysql55/bin/mysql -h127.0.0.1 ----如果是兩台伺服器,在另外一台伺服器需要連線該台伺服器就要使用tcp/ip,socket就無法使用了
welcome to the mysql monitor. commands end with ; or \g.
your mysql connection id is 4
server version: 5.5.60-log source distribution
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> status
--------------
/usr/local/mysql55/bin/mysql ver 14.14 distrib 5.5.60, for linux (x86_64) using readline 5.1
connection id: 4
current database:
current user: root@localhost
ssl: not in use
current pager: stdout
using outfile: ''
using delimiter: ;
server version: 5.5.60-log source distribution
protocol version: 10
connection: 127.0.0.1 via tcp/ip
socket和tcp/ip
當mysql登陸時,同時指定-h和-s,mysql會預設使用tcp/ip的方式連線。
[root@localhost ~]# /usr/local/mysql55/bin/mysql -h127.0.0.1 -s /tmp/mysql.sock
welcome to the mysql monitor. commands end with ; or \g.
your mysql connection id is 5
server version: 5.5.60-log source distribution
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> status
--------------
/usr/local/mysql55/bin/mysql ver 14.14 distrib 5.5.60, for linux (x86_64) using readline 5.1
connection id: 5
current database:
current user: root@localhost
ssl: not in use
current pager: stdout
using outfile: ''
using delimiter: ;
server version: 5.5.60-log source distribution
protocol version: 10
connection: 127.0.0.1 via tcp/ip
MySQL 兩種登入方式
可以參考我的 mysql 用批處理指令碼bat快速啟動 關閉mysql 或者在計算機的服務那裡開啟,設為手動或自動 即開始選單的mysql5.5 command line client 登入 mysql h主機名 p埠號 u使用者名稱 p密碼 如mysql h localhost p 3306 u ...
Oracle兩種登入認證方式
oracle 資料庫通過 sqlnet.ora 檔案中的引數 sqlnet.authentication services,引數檔案中的 remote login passwordfile 和口令檔案 pwdsid.ora 三者協同作用實現身份認證 sqlnet.authentication ser...
Oracle兩種登入認證方式
轉 oracle 資料庫通過 sqlnet.ora 檔案中的引數 sqlnet.authentication services,引數檔案中的 remote login passwordfile 和口令檔案 pwdsid.ora 三者協同作用實現身份認證.sqlnet.ora檔案 d study or...