(1)下载mysql到/usr/local/src/目录下
cd /usr/local/src/
wget http://syslab.comsenz.com/downloads/linux/mysql-5.1.40-linux-i686-icc-glibc23.tar.gz
(2)解压并将解压完成的数据移动到/usr/local/mysql(这一步是移动并重命名,并不是把数据移到这个目录下,本身这个目录是不存在的)
[[email protected] src]# tar zxvf /usr/local/src/mysql-5.1.40-linux-i686-icc-glibc23.tar.gz
[[email protected] src]# mv mysql-5.1.40-linux-i686-icc-glibc23 /usr/local/mysql
(3)建立mysql用户
[[email protected] src]# useradd -s /sbin/nologin -M mysql
(4)初始化数据库
[[email protected] src]# cd /usr/local/mysql
[[email protected] mysql]# mkdir -p /data/mysql ; chown -R mysql:mysql /data/mysql
[[email protected] mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
(5)拷贝配置文件以及启动脚本并修改其属性
[[email protected] mysql]# cp support-files/my-large.cnf /etc/my.cnf
[[email protected] mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[[email protected] mysql]# chmod 755 /etc/init.d/mysqld
(6)修改启动脚本
[[email protected] mysql]# vim /etc/init.d/mysqld
需要修改的地方有 “datadir=/data/mysql” 以及“basedir=/usr/local/mysql”(datadir为前面初始化数据库时定义的目录)
(7)把启动脚本加入到系统服务项,并设定开机启动,启动mysql
[[email protected] mysql]# chkconfig --add mysqld
[[email protected] mysql]# chkconfig mysqld on
[[email protected] mysql]# service mysqld start
(8)如果启动不了,请到 /data/mysql/ 下查看错误日志,这个日志通常是主机名.err. 检查mysql是否启动的命令为:
[[email protected] mysql]# ps aux |grep mysqld