Tag Archives: tool

08 Apr

MySQL Load Data Infile Syntax Generator Tool Download

The LOAD DATA INFILE statement reads rows from a text file into a table at a very high speed. The file name must be given as a literal string.

I have already written the basic how to follow that considering additional cases.

A lot of questions I have seen for loading separated data to MySQL, so here I’ve created a very beginner level excel tool that will allow you to generate the LOAD DATA syntax as per your choices.
Presently sample table name and field/line separators are specified, which you may alter as per your own file.

Load-data-syntax-v1.0

Load-data-syntax-v1.0

Download the sheet here: Load Data

Load Data Syntax:

Options column specifies options that are required for syntaxes generation.
Under Selection column you will choose your option while under Description column, for each Option description is provided.

Using basic knowledge of load data you can quite easily generate the syntax by specifying option, choosing file to be loaded and finally clicking the Syntax button.

Please refer the syntax on MySQL documentation as well.

This is a “early release”, please check for the updates.
If you have any suggestions or bug report please comment / mail.

Thanks.

20 Mar

Working with EditPlus Text Editor-Regular Expression How To

Editplus is a lot better than the regular text editor, Notepad.
From all it’s features I like RegExp Support the most, and than comes the block select feature.
Here are the quick lines to carry out regular tasks using regular expression in Editplus. It’s kinda downloadable cheetsheet list.

Remove all empty lines:

Find: “^\n” (Ignore double-quotes in all find/replace)
Replace: “”
Where,
^ – Beginning of the line
\n – New Line

Remove Multiple Spaces convert into single space:

Find: ” +”
Replace: ” “
Where,
+ – find one or more occurance of space character.

Comment multiple line of code:

Find: “^”
Replace: “#” or “//”
You may optionally use: Edit Menu > Format > Line Comment.
Generate Comma Separated List from new line delimited list:

Find: “\n”
Replace: “, “
This helps in even joining some of lines of code instead of replacing by comma you may replace it with “”.

Manipulate columns display order / punctuation:

Find: “([0-9]+)\t([a-zA-Z]+)”
Replace: “\2\t\1″
Where,
[0-9]+ – Finds one or more digits
[a-zA-Z]+ – Finds one or more characters
() – mark the block or capture the group
\2 – 2nd mark expression
Eg:
123 abc
345 cde
567 efg
Becomes:
abc 123
cde 345
efg 567
The Other Way:
- Press Alt+C
- Drag you mouse to select respective column and click
- Copy / Cut as required

[ad#ad-2-300×250]

Append / Add semicolon (any character) at the end of the line:

Find: “\n”
Replace: “;\n”

Enclose lines by quotes:

Find: “\n”
Replace: “‘\n'”

Delete all lines containing a given STRING:

Find: “^.*STRING.*$”
Replace: “”

Remove lines not containing a given STRING:

I don’t know how to do this!! :)

Convert tab separated file into insert statements:

TSV: abcd de4 iirn 34399
SQL: INSERT INTO TABLENAME VALUES (“abcd”, “de4″, “iirn”,”34399″);
Find: “(.*)\t(.*)\t(.*)\t(.*)”
Replace: “INSERT INTO TABLENAME VALUES (“\1″, “\2″, “\3″,”\4″);”

Format the telephone number:

Find: “([0-9][0-9][0-9])([0-9][0-9][0-9])([0-9].*)”
Replace: “\1-\2-\3″
Eg.:

Original: 1231231231
Formatted-1: 123-123-1231

Remove Brackets:

Find: “\(|\)”
Replace: “”
Where,
\( – Match (. \ is required to escape marking the expression.
| – or

Replace 1st occurrence of character:

Find: ” (.*)”
Replace: “-\1″
Where,
(.*) – matches everything and marks the block
** Make sure you ignore double-quotes(“) while writing in find / replace boxes.

EditPlus supports following regular expressions in Find, Replace and Find in Files command.

Expression – Description
  • \t – Tab character.
  • \n – New line.
  • . – Matches any character.
  • | – Either expression on its left and right side matches the target string.
  • [] – Any of the enclosed characters may match the target character.
  • [^] – None of the enclosed characters may match the target character.
  • * – Character to the left of asterisk in the expression should match 0 or more times.
  • + – Character to the left of plus sign in the expression should match 1 or more times.
  • ? – Character to the left of question mark in the expression should match 0 or 1 time.
  • ^ – Expression to the right of ^ matches only when it is at the beginning of line.
  • $ – Expression to the left of $ matches only when it is at the end of line.
  • () – Affects evaluation order of expression and also used for tagged expression.
  • \ – Escape character. If you want to use character “\” itself, you should use “\\”.

Notable Features of Editplus are :

  • Spell checking
  • Regex-based find & replace
  • Encoding conversion
  • Newline conversion
  • Syntax highlighting
  • Multiple undo/redo
  • Rectangular block selection
  • Auto indentation
  • Code folding (Text folding)

Download pdf: Editplus-RegExp.

04 Dec

MySQL master master replication monitor with php code

For monitoring replication we know a lot of tools and codes – but this one is different because I wrote it ;)
Well this is fairly simple php code for monitoring a master master replication setup.

It requires a single shared login id available on both MySQL servers.

It will display in tabular format following details:

  • File: Present binary log
  • Position: Binary log position
  • Io run: Slave IO Thread Running status
  • Sql run: SQL Thread Running status
  • ErrorNum: Error number
  • ErrorMeg: Error message

You can easily stop / start each server’s slave (STOP SLAVE / START SLAVE) with a single click.
It also does provide detailed information of global status variables on same page.
It is auto refreshes by default every 2 seconds to provide updated status of both MySQL Servers in Replication.

In code you just need to adjust following parameters as per requirement:

#host-name & ports for replication servers
$slave = “localhost”;
$master = “localhost”;
$slaveport=3306;
$masterport=3307;


#Refresh rate
$refreshRate=2;


#considered a common username password for accessing both servers#
$username=”root”;
$password=”kedar”;

You can download code here: mysql-replication-monitor.php

MySQL Replication Monitor Using PHP:

mysql-replication-monitor-php

-- Kedar Vaijanapurkar --