简体   繁体   English

无法通过VS2012连接到MySQL

[英]Can not connect to MySQL with VS2012

I am trying to establish connection between my application in C# and MySQL. 我正在尝试在C#应用程序和MySQL之间建立连接。 I have downloaded .NET connector from MySql website. 我已经从MySql网站下载了.NET连接器。 I have installed MySQL server with TYPO3 winstaller, and it is running properly. 我已经用TYPO3 winstaller安装了MySQL服务器,并且它运行正常。

Here is my code: 这是我的代码:

 MySqlConnection con = new MySqlConnection("Server=localhost:8501;Database=drogy;Uid=root;Pwd=;");
 con.Open();

It says that: Unable to connect to any of the specified MySQL hosts. 它说:无法连接到任何指定的MySQL主机。

In PHPMyAdmin I see host as localhost:8501. 在PHPMyAdmin中,我看到主机为localhost:8501。 I am sure that user root has password set to NO and I am also pretty sure about the database name. 我确定用户root的密码设置为NO,并且我也很确定数据库名称。 How can I do this please? 我该怎么做? Thank you 谢谢

  1. you should not mention the password if maybe its should be empty means use the ' ' single quotes in you code. 如果password可能为empty则不要提及password ,这意味着在代码中使用' ' 单引号

  2. And you should remove the ; 并且您应该删除; in after the password like ot;Pwd=;"); you should change like ot;Pwd="); password之后输入ot;Pwd=;");您应该像ot;Pwd=");一样进行更改ot;Pwd=");

  3. if your not add the connector, first of all you should must add the MySQL Connector . 如果不添加连接器,则首先必须添加MySQL Connector

sample code: 样例代码:

"server=localhost:portno; user id=yourusername; password=yourpassword; database=yourdatabasename"

update:1 更新:1

All had happend after moving database files to new location and after updating mysql server. 将数据库文件移动到新位置并更新mysql服务器后,一切都发生了。 All tables with InnoDB engine disappeared from my database. 具有InnoDB引擎的所有表都从我的数据库中消失了。 I was trying to recreate them, but mysql told me 1146: Table 'xxx' doesn't exist all the time until I had recreated my database and restarted mysql service . 我试图重新创建它们,但是mysql告诉我1146: Table 'xxx' doesn't exist在我重新创建数据库并restarted mysql service之前, 1146: Table 'xxx' doesn't exist

I think there's a need to read about InnoDB table binaries. 我认为有必要阅读有关InnoDB表二进制文件的信息。

click here : 1 点击这里:1

* Pwd =;“ *必需的数据库密码在“密码”字段中输入密码并尝试使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM