在Linux上使用Mono连接MySQL数据库

我的测试平台是Ubuntu+Mono1.2.4+MySQL5+Connector/Net 5.1.4,其中Mono和MySQL都是使用apt-get方式安装很方便。MySQL Connector/Net 5.1.4从http://dev.mysql.com/downloads/connector/net/5.1.html 下载Windows Source and Binaries, no installer (ZIP)解压缩得到MySql.Data.dll。
使用gacutil -i MySql.Data.dll把MySql.Data.dll安装到Mono的全局组件目录下。
具体内容参考http://www.mono-project.com/MySQL的例子。
特别提出来的是我第一次编译运行的时候出现这样的错误提示:
MySql.Data.MySqlClient.MySqlException: Unable to connect to any of the specified MySQL hosts
in <0x006c5> MySql.Data.MySqlClient.NativeDriver:Open ()
in <0x00027> MySql.Data.MySqlClient.Driver:Create (MySql.Data.MySqlClient.MySqlConnectionString settings)
in <0x0008d> MySql.Data.MySqlClient.MySqlPool:CreateNewPooledConnection ()
in <0x001b0> MySql.Data.MySqlClient.MySqlPool:GetPooledConnection ()
in <0x0003f> MySql.Data.MySqlClient.MySqlPool:GetConnection ()
in <0x000e5> MySql.Data.MySqlClient.MySqlPoolManager:GetConnection (MySql.Data.MySqlClient.MySqlConnectionString settings)
in <0x00050> MySql.Data.MySqlClient.MySqlConnection:Open ()

不思不得其解,后来找到一个国外的论坛,得到这样的提示:
The most likely cause of this is that MySQL is not configured to accept tcp/ip connections.
See here http://dev.mysql.com/doc/mysql/en/can-not-connect-to-server.html
make sure your /etc/mysql/my.cnf file does not have the "skip-networking" feature enabled. This is the default in some installations and disables tcp/ip connections.
根据提示我把my.cnf中的
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address           = 172.22.60.126
bind-address注释掉,然后重新启动mysql服务器程序sudo /etc/init.d/mysql restart就可以正常连接查询了。
GOOD Luck!

转载于:https://www.cnblogs.com/dyj057/archive/2008/01/22/1048528.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值