1,连接mysql数据库管理器:

Code
string sqlStr = "\"" + string.Format("SELECT * FROM mysql.user") + "\"";
string sentence = string.Format("mysql.exe -h{0} -u{1} -p{2} -e{3}", EditConfig.Ip, EditConfig.DBId, EditConfig.DBPwd, sqlStr); 2,插入数据:

Code
string sql = string.Format("insert into {3}.servermanager(ServerManagerID,ICMSSign,SName,ServerType,SIP,SPort,PSSign,OnLine,OrganizeListID,ICMSServerManagerID) values(1,'{0}','MCServer',4105,'{1}',{2},0,1,1,1)", this.guid, this.mcIP, this.mcPort, EditConfig.LogDBName);
string sqlStr = "\"" + sql + "\"";
string sentence = string.Format("mysql.exe -h{0} -u{1} -p{2} -e{3};", EditConfig.Ip, EditConfig.DBId, EditConfig.DBPwd, sqlStr);3,执行脚本文件:

string sentence = string.Format("mysql.exe -h{0} -u{1} -p{2} -f<\"
{3}\"", EditConfig.Ip, EditConfig.DBId, EditConfig.DBPwd, path);
4,获取mysql的获取数据库中的所有表和视图名(在mysql.data.dll):
show tables
5, 获取mysql数据库中当前表的所有字段名(在mysql.data.dll):
string sql = string.Format("select COLUMN_NAME from information_schema.columns where table_name='{0}'", editTableName);
6,mysql根据表名添加字段(在mysql.data.dll):
string sql = string.Format("alter table {0} add column {1} {2}({3})", editTableName,filedName,filedType,Convert.ToInt32( filedSize));
7,导出mysql数据库icms的数据:
//--注释:--default-character-set=gb2312 为数据库默认编码设置;--opt为快速执行选项;--hex-blob为导出
二进制;--single-transaction 为(可重复执行)-不准确;--compatible=mysql323,mysql40 为兼容的数据库版本;
-R 为导出数据库中所有的存储过程和函数; 下面的strimportList是导出数据库中的视图和表名字的集合

Code

string senicms = string.Format("mysqldump -h{0} -u{1} -p{2} --default-character-set=gb2312 --opt --hex-blob --single-transaction --compatible=mysql323,mysql40 -R {3} {4} > \"
{5}\"", IcmsDB.icmsDbIp, IcmsDB.icmsDbUser, IcmsDB.icmsDbPasswd, "icms", strImportList, filePath);
8,导入mysql数据库icms的数据:

Code
//修改icms数据库的编码
string strFirst = "-e \"alter database icms character set gb2312\"";
string senFirst = string.Format("mysql -h{0} -u{1} -p{2} {3}", IcmsDB.icmsDbIp, IcmsDB.icmsDbUser, IcmsDB.icmsDbPasswd, strFirst);
//导入数据

string sentence = string.Format("mysql -h{0} -u{1} -p{2} icms < \"
{3}\" --default-character-set=gb2312 ", IcmsDB.icmsDbIp, IcmsDB.icmsDbUser, IcmsDB.icmsDbPasswd, filePath);