贵州网站建设公司有哪些支持wordpress免费
web/
2025/9/28 9:27:01/
文章来源:
贵州网站建设公司有哪些,支持wordpress免费,网站服务器如何搭建,宁波大型网站建设文章目录 【MySQL】如何使用Unix Sockets 协议连接MySQL数据库连接MySQL的协议使用Unix Sockets 连接MySQL步骤1#xff1a;确认MySQL服务器已启用Unix Sockets支持步骤2 #xff1a;客户端使用Unix Sockets连接MySQL服务器。例1#xff1a;指定socket路径连接列2#xff1… 文章目录 【MySQL】如何使用Unix Sockets 协议连接MySQL数据库连接MySQL的协议使用Unix Sockets 连接MySQL步骤1确认MySQL服务器已启用Unix Sockets支持步骤2 客户端使用Unix Sockets连接MySQL服务器。例1指定socket路径连接列2 不指定socket路径 Linux环境下hostname为localhost时候默认是socket连接例3指定TCP/IP 连接MySQL 小结 MySQL入门02关于MySQL连接的ABC 【MySQL】如何使用Named Pipe协议(Windows)连接MySQL数据库 【MySQL】如何使用Shared-memory协议(Windows)连接MySQL数据库 【MySQL】如何使用Unix Sockets 协议连接MySQL数据库 【免责声明】文章仅供学习交流观点代表个人与任何公司无关。 编辑|SQL和数据库技术(ID:SQLplusDB)
【MySQL】如何使用Unix Sockets 协议连接MySQL数据库
连接MySQL的协议
在MySQL中可以通过指定 --protocol参数选择连接MySQL的协议。
连接协议Connection Protocals
--protocol{TCP|SOCKET|PIPE|MEMORY}TCP/IP (ALL) -Transmission Control Protocal/Internet Protocal-Connection:local remote-Supports Clasic X protocol
Socket file (Unix including Linux/Mac) -Connection:local -Supports Clasic X protocol
Named Pipe (Win) -Connection:local -Supports Clasic
Shared Memory (Win) -Connection:local -Supports Clasic参考 https://dev.mysql.com/doc/refman/8.0/en/connection-options.html#option_general_protocol 4.2.3 Command Options for Connecting to the Server
使用Unix Sockets 连接MySQL
使用Unix Sockets连接MySQL避免了网络通信的开销和潜在的安全风险因此可以提高性能和安全性。 下面介绍如何使用Unix Sockets连接MySQL的步骤。
步骤1确认MySQL服务器已启用Unix Sockets支持
可以通过检查MySQL配置文件中的socket选项来确认MySQL服务器已启用Unix Sockets支持。 默认情况下socket选项设置为/var/run/mysqld/mysqld.sock。
例
ubuntumysql-vm:~$ mysql -u root -p -h 127.0.0.1 -e select socket
Enter password:
-----------------------------
| socket |
-----------------------------
| /var/run/mysqld/mysqld.sock |
-----------------------------或者
mysql show variables like socket;
--------------------------------------------
| Variable_name | Value |
--------------------------------------------
| socket | /var/run/mysqld/mysqld.sock |
--------------------------------------------
1 row in set (0.00 sec)mysql或者 查看MySQL配置文件的socket 设置。
sudo more /etc/mysql/mysql.conf.d/mysql.cnf
sudo more /etc/mysql/mysql.conf.d/mysqld.cnf[mysqld]
#
# * Basic Settings
#
user mysql
# pid-file /var/run/mysqld/mysqld.pid
# socket /var/run/mysqld/mysqld.sock
# port 3306
# datadir /var/lib/mysql步骤2 客户端使用Unix Sockets连接MySQL服务器。
大多数MySQL客户端都支持Unix Sockets但是需要使用正确的选项来指定路径。 例如使用mysql客户端时可以使用–socket选项来指定Unix Sockets路径。
mysql --socket/var/run/mysqld/mysqld.sock -u username -p其中–socket选项指定Unix Sockets路径-u选项指定用户名-p选项提示输入密码。
例1指定socket路径连接
ubuntumysql-vm:/etc/mysql/mysql.conf.d$ mysql --socket/var/run/mysqld/mysqld.sock -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 24
Server version: 8.0.33-0ubuntu0.22.04.2 (Ubuntu)Copyright (c) 2000, 2023, Oracle and/or its affiliates.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 \s
--------------
mysql Ver 8.0.33-0ubuntu0.22.04.2 for Linux on x86_64 ((Ubuntu))Connection id: 24
Current database:
Current user: rootlocalhost
SSL: Not in use
Current pager: stdout
Using outfile:
Using delimiter: ;
Server version: 8.0.33-0ubuntu0.22.04.2 (Ubuntu)
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8mb4
Db characterset: utf8mb4
Client characterset: utf8mb4
Conn. characterset: utf8mb4
UNIX socket: /var/run/mysqld/mysqld.sock
Binary data as: Hexadecimal
Uptime: 2 hours 13 min 49 secThreads: 2 Questions: 54 Slow queries: 0 Opens: 158 Flush tables: 3 Open tables: 77 Queries per second avg: 0.006
--------------mysql列2 不指定socket路径 Linux环境下hostname为localhost时候默认是socket连接
在Linux环境下hostname为localhost时候默认是socket连接
ubuntumysql-vm:/etc/mysql/mysql.conf.d$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 25
Server version: 8.0.33-0ubuntu0.22.04.2 (Ubuntu)Copyright (c) 2000, 2023, Oracle and/or its affiliates.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 \s
--------------
mysql Ver 8.0.33-0ubuntu0.22.04.2 for Linux on x86_64 ((Ubuntu))Connection id: 25
Current database:
Current user: rootlocalhost
SSL: Not in use
Current pager: stdout
Using outfile:
Using delimiter: ;
Server version: 8.0.33-0ubuntu0.22.04.2 (Ubuntu)
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8mb4
Db characterset: utf8mb4
Client characterset: utf8mb4
Conn. characterset: utf8mb4
UNIX socket: /var/run/mysqld/mysqld.sock
Binary data as: Hexadecimal
Uptime: 2 hours 16 min 42 secThreads: 2 Questions: 59 Slow queries: 0 Opens: 158 Flush tables: 3 Open tables: 77 Queries per second avg: 0.007
--------------mysql例3指定TCP/IP 连接MySQL
ubuntumysql-vm:/etc/mysql/mysql.conf.d$ mysql -u root -p --protocolTCP
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 26
Server version: 8.0.33-0ubuntu0.22.04.2 (Ubuntu)Copyright (c) 2000, 2023, Oracle and/or its affiliates.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 \s
--------------
mysql Ver 8.0.33-0ubuntu0.22.04.2 for Linux on x86_64 ((Ubuntu))Connection id: 26
Current database:
Current user: rootlocalhost
SSL: Cipher in use is TLS_AES_256_GCM_SHA384
Current pager: stdout
Using outfile:
Using delimiter: ;
Server version: 8.0.33-0ubuntu0.22.04.2 (Ubuntu)
Protocol version: 10
Connection: localhost via TCP/IP
Server characterset: utf8mb4
Db characterset: utf8mb4
Client characterset: utf8mb4
Conn. characterset: utf8mb4
TCP port: 3306
Binary data as: Hexadecimal
Uptime: 2 hours 17 min 45 secThreads: 2 Questions: 64 Slow queries: 0 Opens: 158 Flush tables: 3 Open tables: 77 Queries per second avg: 0.007
--------------mysql连接成功进入MySQL客户端提示符后就可以使用标准的MySQL命令来执行查询和操作。
※注意 使用Unix Sockets连接MySQL需要在同一台机器上运行MySQL服务器和客户端Sockets仅支持本地连接。 如果需要在不同的机器上连接MySQL服务器则需要使用TCP/IP连接TCP/IP支持本地或远程连接。
小结
本文介绍了如何使用Unix Sockets连接MySQL数据库的方法。
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/web/83257.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!