以下五个软件包是在安装mysql5.5.x之前必须安装的,不然在进行cmake时会报错。这些软件可以通过下面的链接进行源码安装,也可以通过yum安装

1.安装make编译器

下载地址: http://www.gnu.org/software/make/

1tar zxvf make-3.82.tar.gz
2cd make-3.82
3./configure
4make
5make install

2.安装bison

下载地址:http://www.gnu.org/software/bison/

1tar zxvf bison-2.5.tar.gz
2cd bison-2.5
3./configure
4make
5make install

3.安装gcc-c++

下载地址:http://www.gnu.org/software/gcc/

1tar zxvf gcc-c++-4.4.4.tar.gz
2cd gcc-c++-4.4.4
3./configure
4make
5make install

4.安装cmake

下载地址:http://www.cmake.org/

1tar zxvf cmake-2.8.4.tar.gz
2cd cmake-2.8.4
3./configure
4make
5make install

MySQL从5.5版本开始,通过./configure进行编译配置方式已经被取消,取而代之的是cmake工具。最近cmake站点发现有不能正常访问的问题,也可以通过yum进行安装

5.安装ncurses

下载地址:http://www.gnu.org/software/ncurses/

1tar zxvf ncurses-5.8.tar.gz
2cd ncurses-5.8
3./configure
4make
5make install

6、开始安装MySQL

下载地址:http://dev.mysql.com/http://www.percona.com/downloads/Percona-Server-5.5/Percona-Server-5.5.20-24.1/source/
www.percona.com 下载的是一个mysql的分支版本,其要稳定性和性能上又对原mysql进行了优化。其可以完全兼容mysql并加入了优化的XtraDB存储引擎。
准备工作

 1groupadd mysql 
 2useradd -r -g mysql mysql -s /sbin/nologin
 3tar zxvf mysql-5.5.13.tar.gz 
 4cd mysql-5.5.13 
 5
 6cmake -DMYSQL_DATADIR=/opt/mysql/data
 7-DMYSQL_TCP_PORT=3306
 8-DMYSQL_UNIX_ADDR=/tmp/mysqld.sock
 9-DMYSQL_USER=mysql
10-DDEFAULT_CHARSET=utf8
11-DDEFAULT_COLLATION=utf8_general_ci
12-DEXTRA_CHARSETS=all
13-DWITH_READLINE=1
14-DWITH_SSL=system
15-DWITH_EMBEDDED_SERVER=1
16-DENABLED_LOCAL_INFILE=1
17-DWITH_INNOBASE_STORAGE_ENGINE=1
18-DWITHOUT_PARTITION_STORAGE_ENGINE=1
19
20make 
21make install

configure 与cmake参数对照指南:
http://forge.mysql.com/wiki/Autotools_to_CMake_Transition_Guide

7、配置并启动

1cd /opt/mysql
2chown -R mysql .
3chgrp -R mysql .
4scripts/mysql_install_db --user=mysql
5chown -R root .
6cp support-files/my-medium.cnf /etc/my.cnf

关于my.cnf的详细配置参数请查看我的另一篇日志https://blog.361way.com/my-cnf/971.html, 我目前在用的my.cnf配置如下:

 1[client]
 2port            = 3306
 3socket          = /tmp/mysqld.sock
 4[mysqld]
 5port = 3306
 6socket = /tmp/mysqld.sock
 7log-error = /data/mysql/logs/mysql.err
 8pid-file = /data/mysql/logs/mysql.pid
 9slow_query_log_file = /data/mysql/logs/slow.log
10log = /data/mysql/logs/query_log.log
11user = mysql
12character-set-server = utf8
13skip-character-set-client-handshake
14datadir = /data/mysql/data
15general_log = 1
16slow_query_log = 1
17core-file
18max_connections = 180
19key_buffer_size = 32M
20max_allowed_packet = 1M
21table_open_cache = 1024
22tmp_table_size = 64M
23max_heap_table_size = 64M
24sort_buffer_size = 1M
25read_buffer_size = 1M
26read_rnd_buffer_size = 4M
27myisam_sort_buffer_size = 16M
28query_cache_type = 1
29query_cache_size = 64M
30query_cache_limit = 4M
31thread_cache_size = 180
32wait_timeout = 60
33thread_concurrency = 4
34log-bin=mysql-bin
35binlog_format=mixed
36server-id = 1
37innodb_data_home_dir = /data/mysql/data
38innodb_data_file_path = ibdata1:100M:autoextend
39innodb_log_group_home_dir = /data/mysql/data
40innodb_buffer_pool_size = 128M
41innodb_additional_mem_pool_size = 10M
42innodb_log_file_size = 64M
43innodb_log_buffer_size = 8M
44innodb_flush_log_at_trx_commit = 1
45innodb_lock_wait_timeout = 50
46
47[mysqld_safe]
48character-set-server = utf8
49
50[mysqldump]
51quick
52max_allowed_packet = 16M
53default-character-set = utf8
54
55[mysql]
56no-auto-rehash
57default-character-set = utf8
58
59[myisamchk]
60key_buffer_size = 20M
61sort_buffer_size = 20M
62read_buffer = 2M
63write_buffer = 2M
64
65[mysqlhotcopy]
66interactive-timeout

服务管理相关命令如下

 1bin/mysqld_safe --user=mysql &
 2#启动mysql,看是否成功
 3netstat -tnl|grep 3306
 4另外也可以通过脚本的方式启动,如下:
 5#将mysql的启动服务添加到系统服务中
 6cp support-files/mysql.server /etc/init.d/mysql.server
 7#现在可以使用下面的命令启动mysql
 8service mysql.server start
 9#停止mysql服务
10service mysql.server stop
11#重启mysql服务
12service mysql.server restart
13将mysql服务添加到开机启动项,让mysql服务开机启动
14chkconfig --add mysql.server

完成上面的安装以后,如果还需要进行安全方面的设置请在mysql的bin目录找到脚本mysql_secure_installation,运行并按里面的提示进行安全设置。