我正在尝试使用C#将CSV文件导出到MySQL,但每次执行此操作都会失败。我收到一个错误,因为无法连接到任何指定的MySQL主机。请帮帮我。
public partial class Form1 : Form
{
string connectionStringMySql = "Server=000.000.000.00; Database=test; Uid=test; Pwd=tester;";
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
string strCSVFile = "C:\\Users\\IT-Administrator\\Desktop\\Exploded.csv";
MySqlConnection conn1 = new MySqlConnection(connectionStringMysql);
string strLoadData = "LOAD DATA LOCAL INFILE '" + strCSVFile + "' INTO TABLE synctest.tickets FIELDS TERMINATED BY '|' LINES TERMINATED BY '\\n' ignore 1 lines;";
MySqlCommand cmd1 = new MySqlCommand(strLoadData, conn1);
cmd1.CommandTimeout = 6000;
cmd1.Connection = conn1;
conn1.Open();
cmd1.Prepare();
cmd1.ExecuteNonQuery();
conn1.Close();
}
}
答案 0 :(得分:0)
本地infile必须在mysql服务器上,如果它是远程主机,它将失败。 在远程主机目录上必须可由mysql用户
写入我强烈建议不要使用infile批量加载和转储,除非它是服务器迁移
抱歉英语很差。