此文章主要向大家描述的是在Linux上使用Mono來連接MySQL數據庫的一大絕招,我們大家都知道連接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就可以正常連接查詢了。以上的相關內容就是對在Linux上使用Mono連接MySQL數據庫的介紹,望你能有所收獲。
上述的相關內容就是對在Linux上使用Mono連接MySQL數據庫的描述,希望會給你帶來一些幫助在此方面。