一、系统环境及说明
系统:CentOS6.x_x64 mysql:社区版5.6.21,开源数据库用的最多的mysql,编译安装比较繁琐,yum安装版本比较低且默认安装的位置是/var/下,本次采用官方下载的rpm包,通过脚本自动化安装并定制数据目录到独立分区中(本次为/data1目录)
二、准备安装包
1、官方下载
#https://dev.mysql.com/downloads/mysql/5.6.html#downloads 选择对应的版本和平台软件包:
MySQL-shared-compat-5.6.x-1.el6.x86_64.rpm #x就是你下的版本号以下类同
MySQL-devel-5.6.x-1.el6.x86_64.rpm
MySQL-shared-5.6.x-1.el6.x86_64.rpm
MySQL-client-5.6.x-1.el6.x86_64.rpm
MySQL-test-5.6.x-1.el6.x86_64.rpm
MySQL-server-5.6.x-1.el6.x86_64.rpm
2、本实验用到的包
http://pan.baidu.com/s/1nvn0nUx包含了以下软件包:
MySQL-shared-compat-5.6.21-1.el6.x86_64.rpm
MySQL-devel-5.6.21-1.el6.x86_64.rpm
MySQL-shared-5.6.21-1.el6.x86_64.rpm
MySQL-client-5.6.21-1.el6.x86_64.rpm
MySQL-test-5.6.21-1.el6.x86_64.rpm
MySQL-server-5.6.21-1.el6.x86_64.rpm
三、安装
1、如果是官方下载的请直接执行下面操作
#rpm -ivh MySQL-shared-compat-5.6.x-1.el6.x86_64.rpm #提供基础依赖组件,需要第一个安装
#yum remove mysql-libs -y #御载默认自带的mysql-lib
#yum install libaio -y #安装libiao
#rpm -ivh MySQL-devel-5.6.x-1.el6.x86_64.rpm
#rpm -ivh MySQL-shared-5.6.x-1.el6.x86_64.rpm
#rpm -ivh MySQL-client-5.6.x-1.el6.x86_64.rpm
#rpm -ivh MySQL-test-5.6.x-1.el6.x86_64.rpm
#rpm -ivh MySQL-server-5.6.x-1.el6.x86_64.rpm
2、本实验脚本如下:
#!/bin/bash src_dir=$(pwd) cd $src_dir tar xvf mysql5.6.21.x86_64.rpms.tar.gz tar xvf mysql5.6.21.x86_64.rpms.tar cd mysql5.6.21 rpm -ivh MySQL-shared-compat-5.6.21-1.el6.x86_64.rpm yum remove mysql-libs -y yum install libaio -y rpm -ivh MySQL-devel-5.6.21-1.el6.x86_64.rpm rpm -ivh MySQL-shared-5.6.21-1.el6.x86_64.rpm rpm -ivh MySQL-client-5.6.21-1.el6.x86_64.rpm rpm -ivh MySQL-test-5.6.21-1.el6.x86_64.rpm rpm -ivh MySQL-server-5.6.21-1.el6.x86_64.rpm #service mysql start && echo "mysql5.6.21 has installes sucess!" #mysql_root_pwd=`gawk -F : ‘{ print $4 }‘ /root/.mysql_secret` #echo "A random root password has been set. You will find it in ‘/root/.mysql_secret‘." #echo "The random root password was:‘${mysql_root_pwd// }‘" service mysql stop [ -d /data1/mysqldb/data ] || mkdir -p /data1/mysqldb/data [ -d /data1/mysqldb/log ] || mkdir -p /data1/mysqldb/log chown mysql.mysql /data1/mysqldb -R cd /usr/bin ./mysql_install_db --user=mysql --basedir=/usr --datadir=/data1/mysqldb/data #迁移数据目录到/data1/mysqldb/data下可自行定制 cd $src_dircp ${src_dir}/my.cnf /etc cd /var/lib mv mysql /tmp service mysql start && echo "Mysql root password was empty.Please change when you login mysql."
四、注意问题
1、关闭selinux否则脚本安装不成功
2、安装后系统自带的postfix和crontab工具被御了,重新yum安装 一次即可
3、mysql服务的root密码为空,请自行修改root密码
或在脚本中添加以下行 在mysql迁移好目录启动后自动修改mysql root密码
mysqladmin -u root password "123.com"