1、yum安装依赖包
yum install wget gcc gcc-c++ make cmake ncurses-devel libtool zilib-devel -y
2、创建mysql用户
useradd -s /sbin/nologin -M mysql
3、拷贝解压mysql的tar包
cp mysql-5.5.28.tar.gz /usr/local/
tar -zxvf mysql-5.5.28.tar.gz
4、编译安装mysql
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql
-DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock
-DDEFAULT_CHARSET=utf8
-DDEFAULT_COLLATION=utf8_general_ci
-DWITH_EXTRA_CHARSETS:STRING=utf8,gbk
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_READLINE=1
-DENABLED_LOCAL_INFILE=1
-DMYSQL_DATADIR=/data/mysql/
-DMYSQL_USER=mysql
-DMYSQL_TCP_PORT=3306
make && make install
5、修改mysql配置文件
cp support-files/my-medium.cnf /etc/my.cnf
cp support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
6、初始化mysql
bash scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/
7、启动服务
/etc/init.d/mysqld start
8、配置mysql用户
/usr/local/mysql/bin/mysqladmin -u root password 123
/usr/local/mysql/bin/mysql -u root -p
9、设置开机自启动
chkconfig mysqld on
chkconfig --list | grep mysqld