MySQL
下载地址:http://rj.baidu.com/soft/detail/12585.html?ald
1、下载mysql(zip压缩包),直接复制到要安装的位置,无需安装。
2、配置环境(计算机-》属性-》高级系统设置-》高级-》环境变量-》系统变量-》编辑 path:bin文件路径)
3、cmd->启动mysql
//.........................................................
//.........................................................
在 Windows 命令提示符下运行:
启动: net start MySQL
停止: net stop MySQL
卸载: sc delete MySQL
登录:mysql -u root -p 回车 (root无登录密码,直接回车)
参考地址:http://www.cnblogs.com/mr-wid/archive/2013/05/09/3068229.html#d2
显示所有数据库:
show databases;
显示某个数据库里所有表:
use 数据库名;
show tables;
查看表结构:
show columns from 表名;
创建数据库(字符编码为utf8):
create database vmas_419001 character set utf8;
创建表:
create table TableName
(
id int unsigned not null auto_increment primary key,
DataTTIME DateTime not null
);
删除表:
drop table 表名;
退出登录:exit或quit
注意: MySQL语句以分号(;)作为语句的结束, 若在语句结尾不添加分号时, 命令提示符会以 -> 提示你继续输入(有个别特例, 但加分号是一定不会错的);
提示: 可以使用 show databases; 命令查看已经创建了哪些数据库。
//.........................................................
//.........................................................
MySQL ODBC
下载地址:http://download.csdn.net/detail/u010940770/6519079
1、下载Mysql的ODBC链接驱动
2、安装
ODBC
3、开始->设置->控制面板->数据源(ODBC)
4、创建新数据源
测试连接MySQL代码
<pre name="code" class="csharp">using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.Odbc;
namespace TestMysqlConnection
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//check mysql-odbc connection
private void button1_Click(object sender, EventArgs e)
{
//----------------------第三种----------------------
//ODBC连接
string strUser = "";
string strHost = "";
string conString = "DSN=mysql"; //hbjMSM_mysql表示ODBC的用户数据源名
string sql = "select * from user"; //user为用户数据源绑定的数据库中的一个表
OdbcConnection con = new OdbcConnection(conString);
try
{
con.Open();
OdbcCommand com = new OdbcCommand(sql, con);
OdbcDataReader DbReader = com.ExecuteReader();
//int i = Convert.ToInt32(com.ExecuteScalar());
while (DbReader.Read())
{
strUser += DbReader.GetString(0) + ";";
strUser += DbReader.GetString(1) + ";";
strUser += DbReader.GetString(2) + ";";
strUser += DbReader.GetString(3) + ";";
strUser += DbReader.GetString(4) + ";";
strUser += "\n";
//Console.WriteLine("Host = {0} and User = {1}", DBReader.GetString(0), DBReader.GetString(1));
}
MessageBox.Show("User中的用户有:" + strUser + "。");
con.Close();
}
catch (System.Exception ee) { }
finally
{
con.Close();
}
----------------------第二种方法----------------------
//string constr = "DRIVER={MySQL ODBC 5.3 ANSI Driver};" +
// "SERVER=localhost;" +
// "DATABASE=mysql;" +
// "UID=root;" +
// "PASSWORD=;" +
// "OPTION=3";
//MessageBox.Show("开始");
//OdbcConnection con = new OdbcConnection(constr);
//MessageBox.Show("连接成功");
//con.Open();
//MessageBox.Show("关闭连接");
//con.Close();
//----------------------第一种方法----------------------
// 建立数据库连接
//hbjMSM_mysql DBConn; DBConn = new hbjMSM_mysql(new MySQLConnectionString("localhost", "mysql", "root", "", 3306).AsString); DBConn.Open();
执行查询语句
//MySQLCommand DBComm; DBComm = new MySQLCommand("select Host,User from user", DBConn);
读取数据My
//SQLDataReader DBReader = DBComm.ExecuteReaderEx();
显示数据
//try
//{
// while (DBReader.Read())
// {
// Console.WriteLine("Host = {0} and User = {1}", DBReader.GetString(0), DBReader.GetString(1));
// }
//}
//finally
//{
// DBReader.Close(); DBConn.Close();
//}
关闭数据库连接DBConn.Close();
}
//select
private void button3_Click(object sender, EventArgs e)
{
string strUser = "";
string conString = "DSN=hbjMSM"; //hbjMSM表示ODBC的用户数据源名
string sql = "select * from sms_outbox"; //sms_outbox为用户数据源绑定的数据库中的一个表
OdbcConnection con = new OdbcConnection(conString);
try
{
con.Open();
OdbcCommand com = new OdbcCommand(sql, con);
OdbcDataReader DbReader = com.ExecuteReader();
//int i = Convert.ToInt32(com.ExecuteScalar());
while (DbReader.Read())
{
strUser += DbReader.GetString(0) + ";";
strUser += DbReader.GetString(1) + ";";
strUser += DbReader.GetString(2) + ";";
strUser += DbReader.GetString(3) + ";";
strUser += DbReader.GetString(4) + ";";
strUser += "\n";
//Console.WriteLine("Host = {0} and User = {1}", DBReader.GetString(0), DBReader.GetString(1));
}
MessageBox.Show("User中的用户有:" + strUser + "。");
con.Close();
}
catch (System.Exception ee) { }
finally
{
con.Close();
}
}
/*test-begin*/
// test insert
private void button4_Click(object sender, EventArgs e)
{
string strTest = "11111111111111";//测试字段
string conString = "DSN=hbjMSM;" + "UID=root;" + "PWD=;";
//string conString = "DSN=hbjMSM"; //hbjMSM_mysql表示ODBC的用户数据源名(数据库:vmas_419001)
string sql = "insert into test(cTest) values(5555555)"; //test为用户数据源绑定的数据库中的一个表
OdbcConnection con = new OdbcConnection(conString);
try
{
con.Open();
OdbcCommand com = new OdbcCommand(sql, con);
//int i=com.ExecuteNonQuery();//要执行语句,否则语句无效
int i = Convert.ToInt32(com.ExecuteScalar());
MessageBox.Show(i.ToString());
con.Close();
}
catch (System.Exception ee) { }
finally
{
con.Close();
}
}
//test select
private void button5_Click(object sender, EventArgs e)
{
string strUser = "";
string conString = "DSN=hbjMSM;" + "UID=root;" + "PWD=;";
//string conString = "DSN=hbjMSM"; //hbjMSM表示ODBC的用户数据源名
string sql = "select * from test"; //sms_outbox为用户数据源绑定的数据库中的一个表
OdbcConnection con = new OdbcConnection(conString);
try
{
con.Open();
OdbcCommand com = new OdbcCommand(sql, con);
OdbcDataReader DbReader = com.ExecuteReader();
//int i = Convert.ToInt32(com.ExecuteScalar());
while (DbReader.Read())
{
strUser += DbReader.GetString(0) + ";";
strUser += DbReader.GetString(1) + ";";
strUser += "\n";
//Console.WriteLine("Host = {0} and User = {1}", DBReader.GetString(0), DBReader.GetString(1));
}
MessageBox.Show("User中的用户有:" + strUser + "。");
con.Close();
}
catch (System.Exception ee) { }
finally
{
con.Close();
}
}
/*test-end*/
}
}