|
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 mysqli_connect() function. When specifying the server parameter in mysqli_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 © 2024 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 |