Reputation: 916
I have Raspberry Pi with IP = 192.168.137.165 and my Windows laptop has IP = 192.168.137.1. I write C# code to connect MySQL from my laptop.
I also have changed file my.cnf on ras PI as follows:
#bind-address = 127.0.0.1
bind-address = 0.0.0.0
And on MySQL, configure to allow access from any IP address:
GRANT ALL PRIVILEGES ON luan_van.* TO 'root_b'@'%' IDENTIFIED BY 'root';
flush privileges;
Here my C# code:
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);
}
}
}
}
And it error "Can't get hostname for your address"
What wrong with it, and how can I fix it?
Upvotes: 1
Views: 2493
Reputation: 6793
You can use this in your conf file
[mysqld]
skip-name-resolve
That should cure the issue
Upvotes: 1