//连接mysql的参数设置 服务器ip 端口号 数据库名称 用户名 密码
string connectstr = "server=127.0.0.1;port=3306;database=mygame;user=root;password=1234";
//连接数据库
MySqlConnection connection = new MySqlConnection(connectstr);
connection.Open();
//数据库的增删改查
//string command = "insert into users(username,password) values('天下','000')";
//MySqlCommand mySqlCommand = new MySqlCommand(command, connection);
//int count = mySqlCommand.ExecuteNonQuery();
//Console.WriteLine(count);
string command = "select count(username)from mygame.users;";
MySqlCommand mySqlCommand = new MySqlCommand(command, connection);
object o = mySqlCommand.ExecuteScalar();
Console.WriteLine(Convert.ToInt32(o));
}
catch (Exception e)
{
Console.WriteLine(e);
}
C# 连接mysql
最新推荐文章于 2023-06-27 21:19:40 发布