1.下载mysql-connector-net-8.0.12并安装,在引用里添加Mysql.Data。
2.using MySql.Data.MySqlClient;这句话要写上。如图所示
3. 创建连接字符串,其中如果不写 SslMode = none 这句话会报错
“MySql.Data.MySqlClient.MySqlException”类型的未经处理的异常在 MySql.Data.dll 中发生 ,
其他信息: The host localhost does not support SSL connections.
string str = "Server=localhost;User Id=root;Password=hermione9;Database=demo;SslMode = none;";
MySqlConnection con = new MySqlConnection(str);//实例化链接
附上我写的练习注册小程序,实现信息录入Mysql数据库