创建一个Mysql数据库 [英] Creating a Mysql Database

查看:78
本文介绍了创建一个Mysql数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,



如果服务器中不存在使用csharp应用程序,我想创建一个mysql数据库(包含1个表),请帮助

hello,

I want to create a mysql database (contains 1 table) if it not exists in the server by using a csharp application, please help

推荐答案

显而易见的方法是在应用程序中将空DB作为资源,并将其写入文件系统。但是,执行脚本来创建数据库和表也是一项非常简单的任务。
The obvious way to do this is to simply make an empty DB a resource in your app and write it out to the file system. Executing scripts to create a DB and a table are, however, also trivial tasks.


您需要下载并安装MySQL Connector / Net ADO.NET库。一旦您将MySql.Data.dll程序集添加为项目的引用或将其放在/ bin文件夹中,您就可以开始编写代码来访问MySQL。下面是连接到MySQL并从verse表中检索所有行到DataSet的示例。

//典型本地MySQL安装的连接字符串

string cnnString =Server = localhost; Port = 3306; Database = versedb; Uid = root; Pwd = MySecretPassword;



//创建连接对象和数据适配器

MySqlConnection con = new MySqlConnection(cnnString);

MySqlDataAdapter adapter = new MySqlDataAdapter();



//创建一个SQL命令对象

MySqlCommand cmd = new MySqlCommand(SELECT * FROM product,con);



//创建一个填充a数据集

DataSet ds = new DataSet();

adapter.SelectCommand = cmd;

adapter.Fill(ds);



//绑定数据集

// ...将数据绑定代码放在这里......
You will need to download and install the MySQL Connector/Net ADO.NET library. Once you’ve added the MySql.Data.dll assembly as a reference to your project or placed it in your /bin folder, you are ready to start writing code to access MySQL. Here is an example of connecting to MySQL and retrieving all of the rows from the verse table into a DataSet.
// Connection string for a typical local MySQL installation
string cnnString = "Server=localhost;Port=3306;Database=versedb;Uid=root;Pwd=MySecretPassword";

// Create a connection object and data adapter
MySqlConnection con = new MySqlConnection(cnnString);
MySqlDataAdapter adapter = new MySqlDataAdapter();

// Create a SQL command object
MySqlCommand cmd = new MySqlCommand("SELECT * FROM product", con);

// Create a fill a Dataset
DataSet ds = new DataSet();
adapter.SelectCommand = cmd;
adapter.Fill(ds);

// Bind the DataSet
// ... Place your databinding code here ...


hi


有mySql连接器。使用它你可以连接到mySql



http://bitdaddys.com /MySQL-ConnectorNet.html [ ^ ]



使用sql命令发出数据库创建查询



在创建使用之前检查数据库是否存在



创建数据库如果不存在your_database_name



更多参考参考



http://dev.mysql.com/doc/refman/5.0 /en/create-database.html [ ^ ]
hi
There is mySql connector. Using that you can connect to mySql

http://bitdaddys.com/MySQL-ConnectorNet.html[^]

issue your database creating query using the sql command

To check if database exists before creating use

CREATE DATABASE IF NOT EXIST your_database_name

for more reference refer

http://dev.mysql.com/doc/refman/5.0/en/create-database.html[^]


这篇关于创建一个Mysql数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆