串連MySQL資料庫的兩種方式介紹

來源:互聯網
上載者:User
串連MySQL資料庫的兩種方式介紹

串連MySQL操作是串連進程和MySQL資料庫執行個體進行通訊。從開發的角度來說,本質上是進程通訊,常用的進程通訊方式有管道、具名管道、命名字、TCP/IP通訊端、Unix網域名稱通訊端

 

TCP/IP串連:

         TCP/IP通訊端串連方式是MySQL在任何平台都提供的一種串連方式,也是網路中使用最多的一種方式。這種方式在TCP/IP串連上建立一個基於網路的串連請求,一般情況下用戶端在一台伺服器上,而MySQL執行個體在另外一台伺服器上,這兩台機器通過TCP/IP網路連接

mysql> use mysql;Readingtable information for completion of table and column namesYoucan turn off this feature to get a quicker startup with -ADatabasechangedmysql>select user,host,password from user;+------+-------------------+-------------------------------------------+|user | host              | password                                  |+------+-------------------+-------------------------------------------+|root | localhost         |*23AE809DDACAF96AF0FD78ED04B6A265E05AA257 ||root | server.sxkeji.com |                                           ||root | 127.0.0.1         |                                           ||      | localhost         |                                           ||      | server.sxkeji.com |                                           || wu  | %                 |*00A51F3F48415C7D4E8908980D443C29C69B60C9|+------+-------------------+-------------------------------------------+6rows in set (0.01 sec) mysql>

首先遠端連線的用戶端串連的使用者有許可權才可以被串連,我們查看到了wu這個使用者允許任何機器遠端連線

# mysql -h192.168.0.110 -uwu -pEnterpassword:Welcometo the MySQL monitor.  Commands end with; or \g.YourMySQL connection id is 16Serverversion: 5.1.52 Source distribution Copyright(c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.Thissoftware comes with ABSOLUTELY NO WARRANTY. This is free software,andyou are welcome to modify and redistribute it under the GPL v2 license Type'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>

//顯示串連成功

 

Unix域通訊端串連:

在Linux和Unix環境下,還可以使用Unix域通訊端串連。Unix域通訊端其實不是網路通訊協定,所以只能使用MySQL用戶端和資料庫執行個體在同一台伺服器上的情況下使用。可以在設定檔中指定通訊端檔案路徑,如-socket=/tmp/mysql.sock。當資料庫啟動之後使用如下方法尋找通訊端

mysql>show variables like 'socket'\G***************************1. row ***************************Variable_name:socket        Value: /var/lib/mysql/mysql.sock1row in set (0.00 sec)mysql>

 

然後就可以通過通訊端的方式串連了

# mysql -uwu -S /var/lib/mysql/mysql.sockWelcometo the MySQL monitor.  Commands end with; or \g.YourMySQL connection id is 18Serverversion: 5.1.52 Source distributionCopyright(c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.Thissoftware comes with ABSOLUTELY NO WARRANTY. This is free software,andyou are welcome to modify and redistribute it under the GPL v2 licenseType'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.