MySQL replication

More brain dumping, this time after setting up MySQL on my test server to replicate offsite as the data on there is becoming important.

To start with both machines are running fully updated and upgraded Debian Etch and MySQL 5 as a Debian package with identical copies of the MySQL databases in /var/lib/mysql/.

On the master I:

I ensured that bind-address was set to the machine’s IP address as by default it is bound to localhost (therefore not allowing external connections) in /etc/mysql/my.conf

Checked that the server-id and log_bin were set in /etc/mysql/my.conf

Issued the MySQL command GRANT REPLICATION SLAVE ON *.* TO 'USERNAME'@'SLAVE_IP' IDENTIFIED BY 'PASSWORD';

Issued the MySQL command FLUSH TABLES WITH READ LOCK; and then SHOW MASTER STATUS;, noting down the values of File and Position.

On the slave I:

Checked that the server-id and log_bin were set in /etc/mysql/my.conf (server-id being different to that of the master)

Issued the mysql command:

CHANGE MASTER TO MASTER_HOST='MASTER_IP',
MASTER_USER='USERNAME',
MASTER_PASSWORD='PASSWORD',
MASTER_LOG_FILE='FILE_NOTED_EARLIER',
MASTER_LOG_POS=POSITION_NOTED_EARLIER;

To check it was all working I used a combination of the MySQL command SHOW SLAVE STATUS; ensuring that all looked OK and simply made changes on the master and saw them appear on the slave.

If the slave is constantly showing “trying to connect” to the master when you show status then to debug make sure that it can telnet to 3306 on the master. If not then you have to ensure that there is network access between the machines and re-check the bind-address on the master.

Nightmare MySQL migration

I’ve been migrating a large number of websites over from one server to another, always an enjoyable task.

So I get to the last one, copy the database over and do the normal mysql import along the lines of:

[code]mysql -ufoo -pbar database_name < database_name.sql[/code]

Errors++

Turns out the Donke^H^H^H^HDeveloper who built the application didn't care about things like reserved words or spaces in the table and field names. Check out this example of a table, made up but containing valid examples:

[mysql]
CREATE TABLE Site-Password (
# ^^^^^^^^^^^^^ HYPHEN and RESERVED WORD
Name of AdviceClient varchar(255) default NULL,
# ^^^^^^^^^^^^^^^^^^^^ SPACES
Date - TEXT varchar(50) default NULL,
# ^^^^^^^^^^^ TWO RESERVED WORDS!, SPACES and HYPHEN
MeetingDate datetime default NULL,
NextMeetingDate datetime default NULL,
Advice Type - 1 varchar(255) default 'Initial Interview',
# ^^^^^^^^^^^^^^^ SPACES, HYPHEN
KEY Key Carer (Key Carer),
# ^^^^^^^^^ RESERVED WORD and SPACES (Genius)
#
);[/mysql]

Anyway, I got it working in the end by hosting it on it's own virtual server, with *exactly* the same version of MySQL (4.0.17) and using the mysqldump flag --quote-names.

Reckon I lost 4 hours on that.

MySQL Workbench

I just downloaded MySQL workbench 1.06 beta. I stumbled across it after finding this message on the DBDesigner forum page:

Dear DBDesigner4 users,

Due to several attacks against the DBDesigner4 forum it has now been closed down.
We simply cannot understand the sick motivation of people to attack Open Source projects.
So please understand that we will not provide any support from now on.

We will continue to host the DBD4 download till the release of the MySQL Workbench,
its successor application that will be an official MySQL product. Then this project will rest in peace.

Immediate impression is that it’s DB Designer with a MySQL badge on it, but I guess that’s a good thing as DB Designer was excellent (albiet a bit buggy). A nice touch is the ‘overview’ button (or press shift) which allow one to zoom out and see the entire schema.

I’ve got a new database to design so I’ll use this tool and possibly post my thoughts later.

[EDIT]
It’s got a pretty serious bug (that has been reported) where deleting a relationship just doesn’t work.

Related
DB Designer
MySQL Workbench forum