Configure a Second MySql Instance on Windows AMP Server, the easy way

EN
Table of Contents

  1. Purpose
  2. Initial Situation
  3. Official Documentation
  4. What should I do ?
  5. Tests
  6. Modifying existing PHP scripts
  7. Conclusion

1. Purpose top next section

FR

Le problème :
Je dispose d'un serveur MySql, mais bien "chargé" : plus que moins d'un Go dans la partition hébergeant le "datadir".
J'ai besoin de traiter des bases de données multi-Go
Je dois donc monter un second serveur, avec un autre datadir (sur une autre partition), et je suis sur Windows 2K (NT 5.0) SP4 avec MySqld tournant en service.
Je souhaite ne pas perturber le serveur MySql existant, qui sert plusieurs sites dans le même DOCUMENT_ROOT.

EN

Purpose :
I have a MySql Server, but it's relatively "loaded" : only less than 1 GB in the partition hosting the "datadir".
I need to manage new multi-GB databases
I thus need to mount a second server with a different datadir (on an other partition), and I am on Windows 2K (NT 5.0) SP4 with MySqld as a service. I don't want to perturbate the existing MySql server, serving multiple websites in a single DOCUMENT_ROOT.

2. Initial Situation top previous next section

FR

Voici la situation initiale pour le serveur principal :

EN

Here's the Initial Situation of the Main Server :


[client]

port=3306

[mysql]

default-character-set=latin1


# SERVER SECTION
# ----------------------------------------------------------------------
#
# The following options will be read by the MySQL Server. Make sure that
# you have installed the server correctly (see above) so it reads this 
# file.
#
[mysqld]

# The TCP/IP Port the MySQL Server will listen on
port=3306

#Path to installation directory. All paths are usually resolved relative to this.
basedir="D:/MySQL/"

#Path to the database root
datadir="S:/datadir/"

# The default character set that will be used when a new schema or table is
# created and no character set is defined
default-character-set=latin1

# The default storage engine that will be used when create new tables when
default-storage-engine=MyISAM

FR[snip reste de la configuration serveur : tailles des tampons etc]
EN[snip rest of configuration file : buffers sizes etc]

3. Official Documentation top previous next section

FR

voici ce que la documentation à http://dev.mysql.com/doc/refman/5.0/fr/multiple-servers.html recommande de modifier :
--port=port_num
--port contrôle le numéro de port des connexions TCP/IP.
--socket=path
--socket contrôle le chemin de la socket sous Unix, et le nom du pipe nommé sous Windows. Sous Windows, il est nécessaire de spécifier un pipe distinct pour les serveurs qui supportent les connexions par pipes nommés.
--shared-memory-base-name=name
Cette option ne sert actuellement que sous Windows. Elle désigne la portion de mémoire partagée, utilisée par Windows pour mettre aux clients de se connecter via la mémoire partagée. Cette option est nouvelle en MySQL 4.1.
--pid-file=path
Cette option ne sert que sous Unix. Elle indique le nom du fichier dans lequel le serveur écrit l'identifiant de processus.

EN

here is what the documentation at http://dev.mysql.com/doc/refman/5.0/en/multiple-servers.html recommands to edit :
--port=port_num
--port controls the port number for TCP/IP connections. (Alternatively, if the host has multiple network addresses, you can use --bind-adress to cause different servers to listen to different interfaces.)
--socket=path
--socket controls the Unix socket file path on Unix and the name of the named pipe on Windows. On Windows, it is necessary to specify distinct pipe names only for those servers that support named-pipe connections.
--shared-memory-base-name=name
This option currently is used only on Windows. It designates the shared-memory name used by a Windows server to allow clients to connect via shared memory. It is necessary to specify distinct shared-memory names only for those servers that support shared-memory connections.
--pid-file=file_name
This option is used only on Unix. It indicates the pathname of the file in which the server writes its process ID.

4. What should I do ? top previous next section

FR

Ces valeurs n'ayant pas été modifiées pour le serveur initial, il ne me reste plus en théorie qu'à fournir des valeurs différentes, non standard, pour ces éléments et le serveur secondaire pourrait tourner.

NB : il me semble qu'il y a bien un "pidfile" sur Windows ; il porte le nom de la machine et se situe dans la racine du "datadir", juste à côté de son homologue ".err" qui contient les erreurs de lancement. Néanmoins, j'essaie de suivre la RTFM documentation et je ne modifie pas cette variable "pid-file" de configuration.

EN

Given those values have not been modified on the Main Server, I am supposed to only have to provide different (non-standard) values for the new instance and it should work.

NB : there seems to me that there is a "pidfile" on Windows ; it bears the name of the machine and is located in the "datadir" root, alongside with the ".err" similar file which contains the startup errors. Nevertheless, I try to follow the RTFM documentation and thus I don't modify the "pid-file" configuration variable.

5. Tests top previous next section

FR

Je vais essayer d'utiliser le même exécutable mysqld (dans mon cas, mysqld-nt.exe ) soit en service supplémentaire, soit à la console. Essayons d'abord la console (on peut fournir en ligne de commande le chemin vers le my.ini à utiliser)
Je crée donc un fichier my.ini identique au premier (gestion mémoire etc) tout en modifiant le port utilisé, le nom du "pipe" nommé et le shared-memory-base-name (avec une valeur arbitraire)

EN

As I'm trying to use the same executable mysqld (in my case mysqld-nt.exe ) either as a supplementary service or as a console application, let's first try the console (you may specify on the command line the my.ini file path to use)
I thus create a second "my.ini" file identical to the first (memory settings etc) while editing the port used, the named pipe name and the shared-memory-base tag (with an arbitrary value)


[client]

port=3307

[mysql]

default-character-set=latin1


# SERVER SECTION
# ----------------------------------------------------------------------
#
# The following options will be read by the MySQL Server. Make sure that
# you have installed the server correctly (see above) so it reads this 
# file.
#
[mysqld]

# The TCP/IP Port the MySQL Server will listen on
port=3307
socket="R:/datadir2/pipe2"
shared-memory-base-name="serveur2"

#Path to installation directory. All paths are usually resolved relative to this.
basedir="D:/MySQL/"

#Path to the database root
datadir="R:/datadir2/"
FR

Puis j'essaie de lancer directement une seconde instance de l'exécutable serveur mysqld avec ce second fichier .ini ; pour augmenter mes chances, j'ai copié la base "mysql" existante dans le "datadir2".
Je vais donc tenter :

mysqld-nt --defaults-file="D:\MySQL\my2.ini"

ça a l'air de fonctionner, je récupère ipso facto dans "datadir2" les fichiers :


athlon64-slow.log
athlon64.pid
athlon64.err

(athlon64 est mon nom de machine, oeuf corse)


Dans le fichier ".err" je vois :


080112  9:25:19 [Note] mysqld-nt: ready for connections.
Version: '5.0.27-community-nt-log'  socket: ''  port: 3307  MySQL Community Edition (GPL)

ça a l'air donc PLUS QUE bon : parfait. Essayons maintenant la connection depuis le client mysql.

EN

Then I try to launch directly a second instance of the server executable mysqld with this second .ini file ; to raise my chances, I copied the existing database "mysql" into the "datadir2".
I will try :

mysqld-nt --defaults-file="D:\MySQL\my2.ini"

It seems to work and I get those files in "datadir2" :


athlon64-slow.log
athlon64.pid
athlon64.err

(athlon64 is my machine name, oeuf corse)


In the ".err" file I see :


080112  9:25:19 [Note] mysqld-nt: ready for connections.
Version: '5.0.27-community-nt-log'  socket: ''  port: 3307  MySQL Community Edition (GPL)

It seems MORE than GOOD : perfect. Let's try connecting from the mysql client.

Microsoft Windows 2000 [Version 5.00.2195]
(C) Copyright 1985-2000 Microsoft Corp.

C:\>mysql --port=3307 --user=root --password
Enter password: *****
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 5.0.27-community-nt-log

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| dvni               |
| mysql              |
| placoplatre        |
+--------------------+
4 rows in set (0.00 sec)
FR

IMPECCABLE.

Aucun problème.

Reste à m'assurer maintenant qu'on peut accéder depuis mon (second) site PHP à ces (nouvelles) données MySql et le problème sera réglé à mon entière satisfaction.

EN

IMPECCABLE.

No problem.

All I have to do now is check that my (new) site in PHP can access the new MySql databases and the problem will be solved completely in line with my expectations.

6. Modifying existing PHP Scripts top previous next section

FR

Il y a deux solutions pour minimiser l'impact sur le code PHP existant :
Soit spécifier un numéro de port différent (puisque le serveur mysql reste nommé "localhost"), soit modifier à la volée via ini_set() la variable mysql.default_port

La première solution est de loin la meilleure, d'autant plus que je place toujours à un endroit unique la configuration de base de données à utiliser.

Test1 : si je ne change rien, je reçois lors du mysql_connect() :
Access denied for user 'root'@'localhost' (using password: YES)
(normal, les mots de passe "root" sont différents entre les deux bases mysql)

Test2 avec le nouveau port 3307 :
ça marche, j'ai le site et les données...

Il suffit de mettre dans le source PHP du sous-site qui a besoin de la nouvelle base de données :


$dbHost='localhost:3307';

C'est cette variable qui est utilisée dans mysql_connect() ou mysql_pconnect()

EN

There are two solutions to minimize the impact of the change on existing PHP scripts :
Either specify a different port number (as the mysql server remains "localhost"), or modify at runtime via ini_set() the variable mysql.default_port

The first solution is by far the best, especially since I always place my DB settings in a unique place for a given website.

Test1 : if I don't change anything, I get at mysql_connect() time :
Access denied for user 'root'@'localhost' (using password: YES)
(normal, both "root" passwords are differents between the two mysql databases)

Test2 with the new port 3307 :
it works, I have my sites and its data...

All you've to do is change your host setting in PHP like this :


$dbHost='localhost:3307';

This is the variable that I use in mysql_connect() or mysql_pconnect()

9. Conclusion top previous section

FR

En conclusion : avec la même instance unique de navigateur, j'ai maintenant accès sans autre formalité à deux serveurs mysql complètement distincts, et à deux jeux de données différents sur deux disques différents, le tout dans la même racine web. Sans avoir eu à me battre pendant des heures ;-)
Best regards,

EN

Conclusion : with the same unique browser instance, I have now access very easily to two different mysql servers concurrently holding their data on different partitions, from sites in the same web root, without having had to struggle for hours ;-)
Best regards,

Vincent Graux (VGR) for European Experts Exchange and Experts Round Table and Edaìn Works  back to list of articles
Last update 2023-12-22 08:38:14