连接MySQL数据库的两种方式介绍
来源:互联网 发布:sqlserver收费吗 编辑:程序博客网 时间:2024/05/20 16:12
连接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>
- 连接MySQL数据库的两种方式介绍
- php7连接mysql数据库的两种方式
- SOL Server2008数据库远程连接和访问数据库的两种方式介绍
- java 连接数据库的两种方式
- 讨论mysql和mysqli两种连接数据库方式
- 两种方式连接数据库
- MySQL连接两种方式
- Mysql数据库的几种连接方式
- [mysql]MySQL 两种连接方式
- 补:JSP连接数据库的两种方式
- ado.net两种连接数据库的方式
- Oracle数据库中表的两种连接方式
- asp.net数据库配置文件连接字符串的两种方式
- oracle连接远程数据库导出数据的两种方式
- JAVA连接数据库的两种方式,JDBC和JNDI
- myeclipse自带的数据库两种连接方式
- Oracle数据库服务器的两种连接方式
- JDBC连接数据库的两种方式----JDBC-0
- Linux TCP/IP 协议栈源码分析
- ORACLE ERP 的前世今生
- 记录Linux学习过程
- ORA-00257 archiver error. 错误的处理方法
- JavaScript跨域总结与解决办法
- 连接MySQL数据库的两种方式介绍
- 将A, B, C , D ... Z, AA, AB...AZ, BA转换为对应的数字
- 40个视差滚动效果网站的新技术应用
- 我的VIM配置(C/C++和PHP)(转载请注明出处)
- 堆排序C语言实现
- String类型与Date类型之间的转换
- jqGrid选项(Option)
- 从一则笑话分析软件开发前期的需求调研精神
- 【VC】各种免费、开源的directui库,duilib,REDUI,UiFeature,sharpui等