在navicat中用“show master logs; ”查看所用的binlog日志文件,结果如上。
 可是在C#程序中获取到的数据用table接收到的,Log_name的值却成了System.Byte[].
当我在配置文件中不指定port端口时获取到的binlog日志文件集中的Log_name就是原样的。
真诚的请教各位,这种问题该如何解决!
本机安装了mysql5.4版本 端口是3306,mysql5.0 端口是3308(自己设置的)。

解决方案 »

  1.   

    C#代码
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.IO;using MySql.Data.MySqlClient;namespace ManagerBinLog
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        private void Form1_Load(object sender, EventArgs e)
            {
                string sqlstr = "show master logs; ";
                DataTable loglist = SqlHelper.GetDataSet(SqlHelper.ConnectionString, CommandType.Text, sqlstr, null).Tables[0];
                string[] arrLogNames = null;
                if (loglist != null && loglist.Rows.Count > 0)
                {
                    //arrLogNames = new string[loglist.Rows.Count];
                    for (int i = 0; i < loglist.Rows.Count; i++)
                    {
                        object obj = loglist.Rows[i]["Log_name"];
                        byte[] bytes = (byte[])obj;                    string s = bytes.ToString();
                        
                    }
                }
                string sql = "show binlog events ; ";
                DataTable dt = SqlHelper.GetDataSet(SqlHelper.ConnectionString, CommandType.Text, sql, null).Tables[0];
            }        private void button1_Click(object sender, EventArgs e)
            {
                string startDate = this.dateTimePicker1.Value.Date.ToString();
                //string endDate = this.dateTimePicker2.Value.Date.ToString();
                string tbname = this.comboBox1.SelectedText;
                string cmd = this.comboBox2.SelectedText;
            }     }
    }app.config代码
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <connectionStrings>
        <add name="TestConnectionString" connectionString="server=localhost;user id=root;password=root; database=mytest; port=3306; pooling=false" providerName="MySql.Data.MySqlClient" />
      </connectionStrings>
    </configuration>
      

  2.   

    用3306默认端口mysql5.4 Server服务 获取到的binlog日志文件集是:
     binlog.000001 789
     binlog.000002 627
    用3308端口mysql5.0 Server服务 获取到的binlog日志文件集是:
     <add name="TestConnectionString" connectionString="server=localhost;user id=root;password=root; database=mytest; port=3308; pooling=false" providerName="MySql.Data.MySqlClient" />
     System.Byte[] 638
     System.Byte[] 305
      

  3.   

    刚把mysql5.4与mysql5.0都卸了重装吧端口调换了!mysql5.0用3306的端口,测试winform程序获取到的Log_name还是System.Byte[]
      

  4.   

    跟端口无关,跟mysql server版本有关。
    5.4里头是好的。5.0有问题。应该是这样子。
    另外:
      object obj = loglist.Rows[i]["Log_name"];
      byte[] bytes = (byte[])obj;  string s = bytes.ToString();
    中间为何要用bytes转换,obj直接可以转成string的。
      

  5.   

    是的,是跟mysql server的版本有关。mysql server5.0安装时选择的是utf8编码。
    object obj = loglist.Rows[i]["Log_name"];
    obj.toString();的方法我也试过了,返回的值还是“System.Byte[]”,不行的。
     Byte[] bt = (Byte[])loglist.Rows[i]["Log_name"];                 
     string s = System.Text.UTF8Encoding.UTF8.GetString(bt);
    用这两句代码可以解决了!
      

  6.   

    是的,是跟mysql server的版本有关。mysql server5.0安装时选择的是utf8编码。
    object obj = loglist.Rows[i]["Log_name"];
    obj.toString();的方法我也试过了,返回的值还是“System.Byte[]”,不行的。
     Byte[] bt = (Byte[])loglist.Rows[i]["Log_name"];  
     string s = System.Text.UTF8Encoding.UTF8.GetString(bt);
    用这两句代码可以解决了!