Custom Search
 


How to connect two different versions of MySQL server on the same computer



This article shows you how to access multiple versions of MySQL server from MySQL client tool SQLyog as well as how to access them by PHP. You should have installed two different versions MySQL server on the same computer.

1. Connect by SQLyog

Two different versions of MySQL server can be accessed by free MySQL client tool - SQLyog. When launching SQLyog, specify the port number that is going to be used to connect to MySQL. In our case, use port 3306 to access MySQL version 4.0 and use port 3307 to access MySQL version 4.1.

To open two MySQL servers in SQLyog, you need to open two instances of SQLyog with different port numbers. But this practice is not recommended because you can easily get confused and may accidentaly change data in a database that is on a different server.

2. Connect by PHP

Two different versions of MySQL server can be accessed by PHP's mysql_connect() function. When specifying the server parameter in mysql_connect(), include the port number that is used by MySQL. Below is the format:

hostname:port

If port number is omitted, the default port number 3306 is assumed. In our case, port 3306 is used by MySQL 4.0.25 and port 3307 is used by MySQL 4.1.18. This way, it is possible that the same web application can access two MySQL servers of different versions.

PHP website connects to northwind database in MySQL 4.0.25 at default port 3306:

define('DB_HOST_1', 'localhost');
define('DB_NAME_1', 'northwind');
define('DB_USER_1', 'root');
define('DB_PASS_1', 'password_1');

$mysql_link_1 = mysql_connect(DB_HOST_1, DB_USER_1, DB_PASS_1) or die("Could not connect to database"); 
mysql_select_db(DB_NAME_1, $mysql_link_1) or die("Could not select database");

The same PHP website connects to northwind database in MySQL 4.1.18 at port 3307:

define('DB_HOST_2', 'localhost:3307');
define('DB_NAME_2', 'northwind');
define('DB_USER_2', 'root');
define('DB_PASS_2', 'password_2');

$mysql_link_2 = mysql_connect(DB_HOST_2, DB_USER_2, DB_PASS_2) or die("Could not connect to database"); 
mysql_select_db(DB_NAME_2, $mysql_link_2) or die("Could not select database");

Happy Connecting!


Copyright© GeeksEngine.com



Related Articles:

1.Steps to install PHP 5.x on Windows as a development machine
2.How to install Apache 2.x web server on Windows
3.How to configure MySQL server 5.1 on Windows
4.How to install MySQL server 5.1 on Windows with screenshots
5.Five ways to create include path for PHP
6.How to use Date and Time data as integer value in PHP and MySQL
7.How to use Apache Virtual Host to run multiple local websites on Windows
8.Install all PEAR packages by yourself
9.How to install PEAR on Windows
10.How to use PHP and Microsoft SMTP Virtual Server to send emails
11.How to install PHP server-side scripting language on Windows
12.How to install Apache 1.3 web server on Windows
13.How to install two different versions of MySQL server on the same PC
14.How to configure MySQL server 4.1 on Windows
15.How to install MySQL server 4.1 on Windows with screenshots
16.Export Northwind Access database to MySQL via ODBC


Other Recent Articles from the WAMP & LAMP category:

1.How to resolve Apache web server port 80 access problem
2.The free tools I use to build PHP and MySQL websites
3.Steps to install PHP 5.x on Windows as a development machine
4.How to install Apache 2.x web server on Windows
5.How to configure MySQL server 5.1 on Windows
6.How to install MySQL server 5.1 on Windows with screenshots
7.How to upgrade from PHP4 to PHP5
8.How to load time zone data for MySQL on Windows
9.How to use Apache Virtual Host to run multiple local websites on Windows
10.Install all PEAR packages by yourself
11.How to install PEAR on Windows
12.How to use PHP and Microsoft SMTP Virtual Server to send emails
13.How to install PHP server-side scripting language on Windows
14.How to install Apache 1.3 web server on Windows
15.How to install two different versions of MySQL server on the same PC
16.How to configure MySQL server 4.1 on Windows
17.How to install MySQL server 4.1 on Windows with screenshots
18.How to set up DSN in ODBC Data Source Administrator on Windows

Copyright © 2017 GeeksEngine.com. All Rights Reserved.

This website is hosted by HostGator.

No portion may be reproduced without my written permission. Software and hardware names mentioned on this site are registered trademarks of their respective companies. Should any right be infringed, it is totally unintentional. Drop me an email and I will promptly and gladly rectify it.

 
Home | Feedback | Terms of Use | Privacy Policy