Tuesday, August 26, 2008

MySQL: Change Default Port Under Linux / UNIX

Q.I'm using MySQL 5 under Red Hat Enterprise Linux 5. How do I change default mysql server port (tcp port 3306) under Linux or UNIX operating systems?

A. MySQL server and client uses a file called my.cnf. You need to open /etc/my.cnf (Global mysqld configuration file) to specify new port.

MySQL Change Default Port

Open /etc/my.cnf file:
# vi /etc/my.cnf
Set new port 5123:
port=5123
Here is is my sample /etc/my.cnf file:

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
port=5123
old_passwords=1
bind = 10.10.29.66
key_buffer = 500M
table_cache = 4000
sort_buffer_size = 3M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
max_connections = 400
query_cache_type = 1
query_cache_limit = 1M
query_cache_size = 100M

max_allowed_packet = 1M
thread_cache_size = 8

# Try number of CPU's*2 for thread_concurrency
thread_concurrency = 4
local-infile=0

[mysql.server]
user=mysql
basedir=/var/lib

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

[mysqldump]
quick
max_allowed_packet = 16M
Save and close the file. Restart mysqld:
# service mysqld restart

No comments: