我有Raspberry Pi,IP = 192.168.137.165,我的Windows笔记本电脑IP = 192.168.137.1。我编写C#代码从我的笔记本电脑连接MySQL。
我也在ras PI上更改了文件my.cnf,如下所示:
#bind-address = 127.0.0.1
bind-address = 0.0.0.0
在MySQL上,配置为允许从任何IP地址进行访问:
GRANT ALL PRIVILEGES ON luan_van.* TO 'root_b'@'%' IDENTIFIED BY 'root';
flush privileges;
这是我的C#代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
namespace bp_3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btn_connect_Click(object sender, EventArgs e)
{
try
{
string constring = "Server=192.168.137.165;Database=luan_van;Port=3306;User ID=root_b; Password=root";
MySqlConnection conDataBase = new MySqlConnection(constring);
MySqlDataAdapter myData = new MySqlDataAdapter();
myData.SelectCommand = new MySqlCommand("select * from tt_nhanvien;", conDataBase);
MySqlCommandBuilder cb = new MySqlCommandBuilder(myData);
conDataBase.Open();
MessageBox.Show("Connect");
conDataBase.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
错误“无法获取您地址的主机名”
它有什么问题,我该如何解决?
答案 0 :(得分:1)
您可以在conf文件中使用它
[mysqld]
skip-name-resolve
这应该可以解决问题