从MySQL5.5 开始就要用cmake安装,so,这里也用到了cmake
一、安装编译工具
yum install gcc gcc-c++
yum install ncurses-devel
二、安装cmake和bison
1.源码安装
# wget http://www.cmake.org/files/v2.8/cmake-2.8.4.tar.gz
# tar zxvf cmake-2.8.4.tar.gz
# cd cmake-2.8.4
# ./bootstrap
# make
# make install
#wget http://ftp.gnu.org/gnu/bison/bison-2.5.tar.gz
#tar zxvf bison-2.5.tar.gz
#cd bison-2.5
#./configure
#make
#make install
2、yum安装
#yum -y install cmake
#yum -y install bison
三、编译安装MySQL
#/usr/sbin/groupadd mysql
#/usr/sbin/useradd -g mysql mysql
#cd /tmp
#tar xvf mysql-5.5.15.tar.gz
#cd mysql-5.5.15/
#cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ #安装到/usr/local/mysql目录
-DMYSQL_UNIX_ADDR=/var/mysql/mysql.sock \ #sock存放到/var/mysql目录
-DDEFAULT_CHARSET=utf8 \ #字符集
-DDEFAULT_COLLATION=utf8_general_ci \ #字符集校验
-DWITH_EXTRA_CHARSETS=all \ #支持所有字符集
-DWITH_MYISAM_STORAGE_ENGINE=1 \ #innoDB引擎
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_DATADIR=/var/mysql/data \
-DMYSQL_USER=mysql
#make
#make install
四、其他设置
#chmod +w /usr/local/mysql
#chown -R mysql:mysql /usr/local/mysql
#ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.18
#mkdir -p /var/mysql/
#mkdir -p /var/mysql/data/
#mkdir -p /var/mysql/log/
#chown -R mysql:mysql /var/mysql/
#cd support-files/
#cp my-huge.cnf /var/mysql/my.cnf #复制配置文件
#cp mysql.server /etc/rc.d/init.d/mysqld #复制启动脚本
#chmod +x /etc/init.d/mysqld
# ./scripts/mysql_install_db --user=mysql --ldata=/var/mysql/data #初始化数据库
#/etc/init.d/mysqld start #启动数据库
五、MYSQL配置
#vim /etc/init.d/mysqld(编辑此文件,查找并修改以下变量内容:)
basedir=/usr/local/mysql
datadir=/var/mysql/data
加入启动项:
#chkconfig --add mysqld
#chkconfig mysqld on
六、问题
安装完成之后启动服务会出现如下出错,
Q:Starting MySQL..The server quit without updating PID file (/var/lib/mysql/localhost.localdomain.pid)
A 解决办法:
确实一般都是my.cnf配置文件的问题
/etc/my.cnf来自以下文件:
如果你的内存≤64M,则复制/usr/local/share/mysql/my-small.cnf为/etc/my.cnf
# This is for a system with little memory (<= 64M) where MySQL is only used
# from time to time and it's important that the mysqld daemon
# doesn't use much resources.
如果内存是128M,则复制/usr/local/share/mysql/my-medium.cnf为/etc/my.cnf
# This is for a system with little memory (32M - 64M) where MySQL plays
# an important part, or systems up to 128M where MySQL is used together with
# other programs (such as a web server)
如果内存是512M,则复制/usr/local/share/mysql/my-large.cnf为/etc/my.cnf
# This is for a large system with memory = 512M where the system runs mainly
# MySQL.
如果内存是1-2G,则复制/usr/local/share/mysql/my-huge.cnf为/etc/my.cnf
# This is for a large system with memory of 1G-2G where the system runs mainly
# MySQL.