c# - Reading MySql binlog -


I do not agree that this question was effectively answered:

My Pass, which I think is the same question: I want to read a MySQL binologue from within the C # application, but do not know the format of the file. How can I parse the data of these files correctly?

First of all, what I learned:

  1. MySQL Most source code files are set up with assemblies and are usually included in [Assinner] \. For example, a specific installation program file \ MySql \ MySql 5.6 \ in.

  2. Do not place the files in that folder. However, I was able to obtain a quick Google search file easily. The file can be found here: It is well documented and easy to read

Second, My solution :.

As told by akuzminsky, the format of the binlog of MySQL is subject to change. However, the format returned from the mysqlbinlog.exe utility is compatible. This application is usually included in a MySQL install and it should be located in the [iriser] \ bin. Now let me run this application from within the C # console application and parse the result. I used the following steps to complete it:

  1. Enable logging on the MySQL server from the option file. In the MySQL workspace, check the 'Log-bin' under the Logging tab. Or, type 'log-bin =' in the settings file (often located in [arcır]. It can be called 'my.ini' or 'my.cnf' or something else. Generally, .cnf or .ini extensions With) a file name is not required when no one is specified, MySQL will automatically create the file name for the log. However, review the MySQL documentation on potential issues with it.

  2. within my client application, I ask to get the path of each binary log server (many may be). To do this:

      query shows global variables such as 'data' // data directory. Query show returns the binary log // Each binary log file name, with its file size (helpful to read).  
    • Parsing this together becomes the path to each binary log.

  3. Since in mysqlbinlog.exe [basedir] \ bin, I get the path of the server query based on directory

      query show global variable like 'basedir'  

    Then, I parse the result with '\ bin mysqlbinlog.exe'

  4. I want to create a new process using the process class, performed using mysqlbinlog each binary log .exe, and other files to read the results in a string variable:

    Private Static String GetLogTexts (Liststring> logfilenames) {From the list & lt; String & gt; _logtexts = new list & lt; String & gt; (); String _bagirir = gatebusadier (); Foreach (string logfilame in logfile name) {Proc Proc = new Process (); Proc.StartInfo.FileName = _basedir + "\\ bin \\ mysqlbinlog"; Proc.StartInfo.Arguments = string.Format ("\" {0} \ "", logfile); Proc.StartInfo.UseShellExecute = false; Proc.StartInfo.RedirectStandardInput = proc.StartInfo.RedirectStandardOutput = True; Proc.Start (); _logtexts.Add (proc.StandardOutput.ReadToEnd ()); } Return _logtexts; } Private Static String GetBaseDir () {string path = ""; (MySqlConnection conn = Using the new MySqlConnection (RemoteServerConnectionString)) {conn.Open (); While (MySqlCommand cmd1 = new MySqlCommand (, Connecticut) " 'basedir' shows such as global variables") using {(MySqlDataReader reader = cmd1.ExecuteReader ()) {while (reader.Read ()) {path using = Reader.getString (1); } } } } return path; }
  5. Finally, I parse the results using the argument (which I see specific) for him. The result is very easy to read: Use mysqlbinlog broken regular line statement delimiter, which statements are terminated by a defined first (as always, could be more than one delimiter) < / P>

  6. I hope it helps someone!


Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -