Powered By Blogger

19 November 2008

เปลี่ยน port mysql ใน AppServ

ในที่นี้ เนื่องจาก ติดตั้ง mysql 2 instance บนเครื่องเดียวกัน
และ มีการ ใช้ port ชนกันจึงต้องเปลี่ยน ที่ ตัวหนึ่้ง
( หลังจาก มีการเปลี่ยน port ของ apache web server ไปแล้ว )
โดยให้ instance ตัวหนึ่ง ใช้ port 3306 ปกติ
และอีกตัว ใช้ port 3307

ต้องการเปลี่ยน port ก็ แก้โดย
C:\AppServ\MySQL\my.ini

เปลี่ยน section
[client]
port=3306

ให้กลายเป็น
[client]
port=3307

หมายเหตุ ในส่วน [client] อาจไม่ต้องแก้ไขก็ได้ เพราะจะ ใช้กับ mysql.exe ซึ่งเป็น client
แต่ server ส่วนใหญ่จะเป็น 3306 อยู่แล้ว อาจแก้ไขเฉพาะ [mysqld] ก็พอ

และต้องเปลี่ยน section mysqld จาก
[mysqld]
# The TCP/IP Port the MySQL Server will listen on
port=3306

ไปเป็น
[mysqld]
# The TCP/IP Port the MySQL Server will listen on
port=3307

แล้ว restart mysql
แล้วอาจทดสอบด้วยการ telnet localhost 3307 ดู

และต้องเปลี่ยน phpMyAdmin อีกให้ มองเห็นตัวนี้ รวมทั้ง เมื่อจะติดต่อด้วย php
ต้องเรียกด้วย
$link = mysql_connect('127.0.0.1:3307', 'mysql_user', 'mysql_password');
หรือ
$link = mysql_connect('example.com:3307', 'mysql_user', 'mysql_password');


แก้ไข ที่ phpMyAdmin ดังนี้
C:\AppServ\www\phpMyAdmin
config.inc.php แก้ไข จาก

cfg['Servers'][$i]['port'] = '';

ให้เป็น
cfg['Servers'][$i]['port'] = '3307';



แล้ว ลอง start mysql ใหม่
และ start phpmyadmin ใหม่ จาก browser

ถ้าทำการเปลี่ยน port ของ apache ต้อง restart apache ใหม่ด้วยครับ

No comments: