I wanted to set up several servers on my machine using the Ubuntu
distribution and control them using
typical way to manage several servers on your machine. However, I also
wanted to use MySQL 5.1 and not 5.0, which is the default on Jaunty
About a month ago, I upgraded to Karmic Koala and one of the reasons
were that MySQL 5.1 is used by default. Even though I could install
the latest revision all the time, I usually want to use the real
distributions for my private projects for a number of reasons.
I actually tried to upgrade to MySQL 5.1 on Ubuntu 9.04, but I discovered that all kinds of applications had dependencies on MySQL 5.0, so I avoided to upgrade at that time.
Anyway, the procedure for installing multiple servers on the same machine is this:
- Shut down the running server.
This is, strictly speaking, not necessary unless you are going to edit the options for the running server, but I do this as a precaution.
- Edit your
my.cnfconfiguration file and add sections for
mysqld_multiand the new servers.
I wanted to add four servers to play with, not counting the one that is already installed and running, so I added sections
mysqld1to mysqld4. Also add a section for mysqld_multi
- Create server directories and database files using
The new servers need to be bootstrapped so that they have all the necessary databases and tables set up.
- Optionally: install an
init.dscript that uses mysqld_multi.
This is currently not very well-supported in Debian (there is actually a comment saying that it is not supported), so I skipped this step. If you feel adventerous, you can always copy the
/usr/share/mysql/mysqld_multi.serveras /etc/init.d/mysql.serveras they suggest in the file, but I will not do it, nor recommend it (because I haven't tried it).
- Start the installed server(s).
Well, not much to say here.
The important options to add are server-id so that each server gets a unique server id (I'm going to replicate between them), port and socket so that you can connect to each of them both when you're on the local machine and from another machine, and pid-file to give each server a unique pid file name (this is important, since the default will not work at all).
Next step is to install the data directories for the servers, which should be trivial:
$ sudo mysql_install_db --user=mysql --datadir=/var/lib/mysqlfoo --basedir=/usr Installing MySQL system tables... 091120 9:40:23 [Warning] Can't create test file /var/lib/mysqlfoo/romeo.lower-test 091120 9:40:23 [Warning] Can't create test file /var/lib/mysqlfoo/romeo.lower-test ERROR: 1005 Can't create table 'db' (errno: 13) 091120 9:40:23 [ERROR] Aborting 091120 9:40:23 [Warning] Forcing shutdown of 2 plugins 091120 9:40:23 [Note] /usr/sbin/mysqld: Shutdown complete Installation of system tables failed! Examine the logs in /var/lib/mysqlfoo for more information. . . .OK, the warning is a warning, but it seems I forgot the permissions on the directory. Checking the write permissions, no problems. Hmmm... checking that I can create the directories and files manually as the
mysqluser, no problems(!)
What on earth is going on?
So updating the AppArmor configuration file
diff --git a/apparmor.d/usr.sbin.mysqld b/apparmor.d/usr.sbin.mysqld index f9f1a37..7a94861 100644 --- a/apparmor.d/usr.sbin.mysqld +++ b/apparmor.d/usr.sbin.mysqld @@ -21,10 +25,20 @@ /etc/mysql/my.cnf r, /usr/sbin/mysqld mr, /usr/share/mysql/** r, /var/log/mysql.log rw, /var/log/mysql.err rw, + /var/log/mysql[1-9].log rw, + /var/log/mysql[1-9].err rw, /var/lib/mysql/ r, /var/lib/mysql/** rwk, + /var/lib/mysql[1-9]/ r, + /var/lib/mysql[1-9]/** rwk, /var/log/mysql/ r, /var/log/mysql/* rw, + /var/log/mysql[1-9]/ r, + /var/log/mysql[1-9]/* rw, /var/run/mysqld/mysqld.pid w, /var/run/mysqld/mysqld.sock w, + /var/run/mysqld/mysqld[1-9].pid w, + /var/run/mysqld/mysqld[1-9].sock w, }
Here is a unified diff of the changes I made to
$ git diff mysql/my.cnf --- a/mysql/my.cnf +++ b/mysql/my.cnf @@ -111,7 +111,46 @@ max_binlog_size = 100M # ssl-cert=/etc/mysql/server-cert.pem # ssl-key=/etc/mysql/server-key.pem +[mysqld_multi] +mysqld = /usr/bin/mysqld_safe +mysqladmin = /usr/bin/mysqladmin +user = root +[mysqld1] +server-id = 1 +pid-file = /var/run/mysqld/mysqld1.pid +socket = /var/run/mysqld/mysqld1.sock +port = 3307 +datadir = /var/lib/mysql1 +log-bin = /var/lib/mysql1/mysqld1-bin.log +log-bin-index = /var/lib/mysql1/mysqld1-bin.index + +[mysqld2] +server-id = 2 +pid-file = /var/run/mysqld/mysqld2.pid +socket = /var/run/mysqld/mysqld2.sock +port = 3308 +datadir = /var/lib/mysql2 +log-bin = /var/lib/mysql2/mysqld2-bin.log +log-bin-index = /var/lib/mysql2/mysqld2-bin.index + +[mysqld3] +server-id = 3 +pid-file = /var/run/mysqld/mysqld3.pid +socket = /var/run/mysqld/mysqld3.sock +port = 3309 +datadir = /var/lib/mysql3 +log-bin = /var/lib/mysql3/mysqld3-bin.log +log-bin-index = /var/lib/mysql3/mysqld3-bin.log + +[mysqld4] +server-id = 4 +pid-file = /var/run/mysqld/mysqld4.pid +socket = /var/run/mysqld/mysqld4.sock +port = 3310 +datadir = /var/lib/mysql4 +log-bin = /var/lib/mysql4/mysqld3-bin.log +log-bin-index = /var/lib/mysql4/mysqld3-bin.log [mysqldump] quick