系统:CentOS6.x_x64
mysql:社区版5.6.21,开源数据库用的最多的mysql,编译安装比较繁琐,yum安装版本比较低且默认安装的位置是/var/下,本次采用官方下载的rpm包,通过脚本自动化安装并定制数据目录到独立分区中(本次为/data目录)
2、准备安装包
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>本实验用到的包
https://pan.baidu.com/s/1kVraS8R 密码: iybx
包含了以下软件包:
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
3、安装
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 /data/mysqldb/data ] || mkdir -p /data/mysqldb/data [ -d /data/mysqldb/log ] || mkdir -p /data/mysqldb/log chown mysql.mysql /data1/mysqldb -R cd /usr/bin ./mysql_install_db --user=mysql --basedir=/usr --datadir=/data/mysqldb/data #迁移数据目录到/data1/mysqldb/data下可自行定制 cd $src_dircp ${src_dir}/my.cnf /etc cd /var/lib mv mysql /tmp mkdir mysql chown mysql.mysql mysql service mysql start && echo "Mysql root password was empty.Please change when you login mysql." ln -s /data/mysqldb/data/mysql.sock /var/lib/mysql/mysql.sock #由于一些mysql工具默认到这里找mysql.sock所以做个软链 3、注意事项 1>mysql服务的root密码为空,请自行修改root密码 或在脚本中添加以下行 在mysql迁移好目录启动后自动修改mysql root密码 |
mysqladmin -u root password "123.com"
原文地址:http://blog.51cto.com/shhlamp/2046130