1)安装前准备
①下载mysql,从官网获取源码包,http://dev.mysql.com/downloads/mysql
#wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.27.tar.gz
#tar xvf mysql-5.6.27.tar.gz
#cd mysql-5.6.27
②检查是否存在mysql
#rpm -qa | grep mysql
存在的话就删除
rpm -e mysql //普通删除模式
rpm -e --nodeps mysql //只删除mysql不删除依赖
③安装编译环境
#yum -y install make gcc-c++ cmake bison-devel ncurses-devel
2)编译安装mysql
#cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
上述配置成功后,开始编译安装,这个过程要等一会
#make && make install
如果这个过程中没有报错,安装完成!
3)配置MySQL
①配置mysql用户(mysql)和用户组(mysql)及其权限
#grep mysql /etc/passwd
#grep mysql /etc/group
如果存在就不创建,不存在就创建
#groupadd mysql
#useradd -g mysql mysql
将/usr/local/mysql的用户和用户组设置为mysql
#chown -R mysql.mysql /usr/local/mysql
②初始化数据库
#cd /usr/local/mysql
#scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql --pid-file=/usr/local/mysql/data/mysql.pid --tmpdir=/tmp/mysql
③启动mysql并设置为开机自启动
#cp support-files/mysql.server /etc/init.d/mysql
#chkconfig mysql on
#service mysql start
④配置环境变量
编辑/etc/source文件,添加以上代码至末尾
PATH=/usr/local/mysql/bin:$PATH
export PATH
让环境变量生效
#source /etc/profile
⑤开启远程访问
#mysql
>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'mypwd123' WITH GRANT OPTION;