Monday, July 27, 2009

Quick MySQL installation tutorial

Updated as per log date and for redhat 32/64 bit installation.

1. Login as root and change directory to /usr/local or where you want to install the mysql. I normally install mysql on /usr/local.

$ cd /usr/local

2. Download the mysql. This is the example of mysql version 5.1.36. You can always navigate in mysql site to find the latest version and paste it after wget.

$ wget http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.36.tar.gz/from/ftp://ftp.oss.eznetsols.org/mysql/

3. Untar the archive.

$ tar -zxvf mysql-5.1.36.tar.gz

4. Go to the directory

$ cd mysql-5.1.36

5. Run configure command

$ ./configure --prefix=/usr/local/mysql --with-unix-sock-path=/tmp/mysql.sock --with-charset=utf8

6. Make and install

$ make
$ make install

7. Copy configuration to /etc folder.

$ cp support-files/my-medium.cnf /etc/my.cnf

8. Setup auto startup.

$ cp support-files/mysql.server /etc/init.d/mysql
$ chmod 755 /etc/init.d/mysql
$ chkconfig --add mysql
$ chkconfig --level 35 mysql on

9. Add mysql user and group for permission.

$ groupadd mysql
$ useradd -g mysql mysql
$ cd /usr/local/mysql/bin/

10. Install default database.

$./mysql_install_db

11. Change var directory ownership to mysql, so that mysql can write to database.

$ cd ..
$ chown -R root .
$ chown -R mysql var
$ chgrp -R mysql .

12. Starting mysql and testing startup.

$ cd bin/
$./mysqld_safe &
$ ps -ef | grep mysql
$ service mysql stop
$ service mysql start

MySQL (my.cnf) which I am using is as following. My servers are quite higher end servers (quad core, 16Gigs, redhat 64bit installation). You can always change settings as per your server configuration to optimize.

[client]
port = 3306
socket = /tmp/mysql.sock

[mysqld]
safe-show-database
old_passwords
back_log = 75
skip-innodb
key_buffer = 192M
myisam_sort_buffer_size = 64M
join_buffer_size = 1M
read_buffer_size = 1M
sort_buffer_size = 2M
table_cache = 2000
thread_cache_size = 384
tmp_table_size = 64M
max_heap_table_size = 64M
max_allowed_packet = 64M
max_connect_errors = 10
read_rnd_buffer_size = 512K
bulk_insert_buffer_size = 8M
query_cache_limit = 10M
query_cache_size = 100M
query_cache_type = 1
query_prealloc_size = 163840
query_alloc_block_size = 32768
default-storage-engine = MyISAM
port = 3306
socket = /tmp/mysql.sock
skip-locking
max_connections=8000
max_user_connections=8000

skip-networking
log-bin=mysql-bin

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash

[isamchk]
key_buffer = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M

[myisamchk]
key_buffer = 64M
sort_buffer = 64M
read_buffer = 16M
write_buffer = 16M

[mysqlhotcopy]
interactive-timeout

[mysqld_safe]
nice=-20
open_files_limit = 8192

No comments:

Post a Comment