The Connect MySQL operation is the connection process and the MySQL DB instance to communicate. From the perspective of development, it is essentially process communication. Common process communication methods are pipelines , Named Pipes , named words ,TCP/IP Sockets , andUNIX domain name sockets . The connection method provided by MySQL is essentially the process of communication mentioned above.
Tcp / ip
TCP/IP Sockets are the connections that MySQL provides on any platform, and is the most used method in the network. In this way, a network-based connection request is established on a TCP/IP connection, in which case the client is on one server, and the MySQL instance is on another server, and the two machines are connected through a TCP/IP network.
For example, I can request a MySQL instance under a remote Linux server under the Windows Server, mysql-h192.168.0.101-uroot-p123456;
The client here is windows, which initiates a TCP/IP connection request to a MySQL instance with a host IP of 192.168.0.101, and the connection is successful. You can then perform some database operations on the MySQL database, such as DDL and DML.
PS: When connecting to a MySQL instance via TCP/IP, MySQL checks a permission view to determine whether the client IP originating the request is allowed to connect to the MySQL instance.
The view is under MySQL library and the table name is User:
Use MySQL;
Select Host, user from user;
Host can access this database only through LocalHost's IP on behalf of this user (root).
host:%, which indicates that the instance is connected under any IP segment. host:192.168.24.%, which indicates that the instance is connected under any 192.168.24.
Named Pipes and Shared memory
In Windows 2000, Windows XP, Windows 2003, and Windows Vista, and later in the Windows operating system, if two processes that need to communicate on the same server , you can use a named pipe, SQL A named pipe is also used for local connections after the server database is installed by default. In the MySQL database, you need to enable the--enable-named-pipe option in the configuration file. In the version after MySQL 4.1, MySQL also provides a way to connect shared memory, adding--shared-memory to the configuration file. If you want to use shared memory, the MySQL client must also use the-protocol=memory option when connecting.
UNIX domain sockets
UNIX domain sockets can also be used in Linux and UNIX environments. UNIX domain sockets are not actually a network protocol, so they can only be used if the MySQL client and the DB instance are on the same server . You can specify the path to the socket file in the configuration file, such as-socket=/tmp/mysql.sock.
After the DB instance is started, we can use the following command to find the UNIX domain socket file:
Show variables like ' socket ';--Query after login instance
Mysql-uroot-p123456-s/tmp/mysql.sock;
Connection to MySQL