Two Methods for connecting to the MySQL database

Source: Internet
Author: User
Two Methods for connecting to the MySQL database

To connect to MySQL, the connection process communicates with the MySQL database instance. From the perspective of development, Process Communication is essentially a process communication. Common process communication methods include pipelines, named pipelines, naming words, TCP/IP sockets, and Unix domain name sockets.

 

TCP/IP connection:

TCP/IP socket connection is a connection method provided by MySQL on any platform, and is also the most commonly used method in the network. This method creates a network-based connection request on a TCP/IP connection. Generally, the client is on one server while the MySQL instance is on another server, the two machines are connected through the TCP/IP network

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>

First, the user of the remote connection client can be connected only when they have the permission. We can see that the user Wu allows remote connection from any machine.

# 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>

// Display that the connection is successful

 

UNIX domain socket connection:

In Linux and UNIX environments, you can also use Unix domain socket connections. UNIX domain socket is not a network protocol, so it can only be used when the mysql client and database instance are on the same server. You can specify the socket file path in the configuration file, such as-socket =/tmp/MySQL. Sock. After the database is started, use the following method to find the socket:

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

 

Then you can connect to the RDS instance through a socket.

# 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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.