繁体   English   中英

无法连接到远程MySQL数据库

[英]Can't Connect to Remote MySQL Database

我正在尝试连接到我的服务器上的MySQL数据库。 这是我用来连接的小样本:


using System;
using System.Data;
using MySql.Data.MySqlClient;

namespace MySqlTest
{
    class MainClass
    {
        public static void Main (string[] args)
        {
        string connectionString =
          "Server=12.34.546.213;" +
          "Database=Test;" +
          "UID=root;" +
          "Password=password;";
       IDbConnection dbcon;
       dbcon = new MySqlConnection(connectionString);
       dbcon.Open();

我尝试执行此代码时收到以下错误:

Unhandled Exception: MySql.Data.MySqlClient.MySqlException: Access denied for us
er 'root'@'12.34.546.213' (using password: YES)
   at MySql.Data.MySqlClient.MySqlStream.ReadPacket()
   at MySql.Data.MySqlClient.NativeDriver.AuthenticateNew()
   at MySql.Data.MySqlClient.NativeDriver.Authenticate()
   at MySql.Data.MySqlClient.NativeDriver.Open()
   at MySql.Data.MySqlClient.Driver.Open()
   at MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings
)
   at MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection()
   at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection()
   at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver()
   at MySql.Data.MySqlClient.MySqlPool.GetConnection()
   at MySql.Data.MySqlClient.MySqlConnection.Open()
   at MySqlTest.MainClass.Main(String[] args) in c:\Users\dvargo\Documents\Proje
cts\MySqlTest\MySqlTest\Main.cs:line 18
Press any key to continue . . .

任何想法为什么会这样? 如何授予root权限以便我可以访问它?

创建用户以从任何主机(或仅从您要连接的主机)访问:

CREATE USER 'username'@'%' IDENTIFIED BY  'password';

授予db的权限:

GRANT ALL PRIVILEGES ON  `sometable` . * TO  'username'@'%' WITH GRANT OPTION ;

检查mysql配置,默认情况下,允许root用户仅从localhost连接。

http://dev.mysql.com/doc/refman/5.1/en/connection-access.html

您是否编辑了配置文件以允许远程访问?

如果没有,那可能是你的问题。 我不知道在这里发布链接的规则,但搜索谷歌的远程mysql访问将提供一些很好的建议。

暂无
暂无

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

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