1、准备工作
groupadd mysql
useradd -r -g mysql mysql
mkdir /usr/local/mysql/ #创建mysql安装目录
mkdir /data/mysql #创建数据存放目录
chown mysql:mysql -R /data/mysql
yum install -y gcc gcc-c++ libtool autoconf automake imake libxml2-devel expat-devel ncurses-devel cmake bison
wget http://mirrors.sohu.com/mysql/MySQL-5.5/mysql-5.5.43.tar.gz
2、解压源码包,编译安装
tar -zxvf mysql-5.5.43.tar.gz
cd mysql-5.5.43 #进入解压后mysql目录
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/data/mysql/ -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306
make && make install #编译通过过,安装
3、初始化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
cd /usr/local/mysql #进入安装目录
chown -R mysql.mysql . # 授权
./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/data/mysql #初始化数据库
/etc/init.d/mysqld start #启动数据库
4、MySQL配置
chkconfig --add mysqld #添加系统服务
chkconfig mysqld on #添加开机启动
export PATH=$PATH:/usr/local/mysql/bin #添加环境变量
echo ‘PATH=$PATH:/usr/local/mysql/bin‘ >> /etc/profile
service mysqld start/stop
本文出自 “linux---基础篇” 博客,请务必保留此出处http://perin.blog.51cto.com/10410663/1671385
原文地址:http://perin.blog.51cto.com/10410663/1671385