1.在mysql官网上载tar包
MySQL-5.6.30-1.el6.i686.rpm-bundle.tar
进目录cd /home/fuyouling/
解压tar -xvf MySQL-5.6.30-1.el6.i686.rpm-bundle.tar
MySQL-client-5.6.30-1.el7.x86_64.rpm
MySQL-devel-5.6.30-1.el7.x86_64.rpm
MySQL-embedded-5.6.30-1.el7.x86_64.rpm
MySQL-server-5.6.30-1.el7.x86_64.rpm
MySQL-shared-5.6.30-1.el7.x86_64.rpm
MySQL-shared-compat-5.6.30-1.el7.x86_64.rpm
MySQL-test-5.6.30-1.el7.x86_64.rpm
2. 查看是否安装了mysql
rpm –qa |grep mysql
如有安装就先卸载:
rpm -e MySQL-client-community-5.1.40-0.rhel5
rpm -e MySQL-server-community-5.1.40-0.rhel5
3. 查看是否安装了mariadb
rpm -qa | grep mariadb
如有安装就先卸载
rpm -e --nodeps mariadb-libs-5.5.35-3.el7.x86_64
rpm -e --nodeps mariadb-5.5.35-3.el7.x86_64
rpm -e --nodeps mariadb-server-5.5.35-3.el7.x86_64
4.按顺序以下安装
yum install -y MySQL-shared-compat-5.6.30-1.el6.i686.rpm
yum install -y MySQL-server-5.6.30-1.el6.i686.rpm
yum install -y MySQL-client-5.6.30-1.el6.i686.rpm
yum install -y MySQL-devel-5.6.30-1.el6.i686.rpm
yum install -y MySQL-shared-5.6.30-1.el6.i686.rpm
5.yum install -y perl-Module-Install.noarch #安装perl Module
6./usr/bin/mysql_install_db #数据库初始化
安装后数据文件目录是在/var/lib/mysql/
配置文件是在/usr/my.cnf
7.chown -R mysql:mysql /var/lib/mysql #赋权限
8.service mysql start #开启mysql服务
9.mysqladmin -u root password ‘123456‘ #设置初次密码
10.mysql -uroot -p123456 #登录mysql
11.service mysql stop #关掉mysql服务
---------------------------------------------------------------
以下为配置多实例:
12.mkdir -p /home/fuyouling/mutl_mysql/mysql_3307/mysql/ #创建数据文件目录
13./usr/bin/mysql_install_db --datadir=/home/fuyouling/mutl_mysql/mysql_3307/mysql --user=root #新实例初始化
14.修改/usr/my.cnf配置,修改为多实例模式
[mysqld_multi]
mysqld=/usr/bin/mysqld_safe
mysqladmin=/usr/bin/mysqladmin
user=root
[mysqld3306]
port=3306
socket=/var/lib/mysql/mysql.sock
pid-file=/var/lib/mysql/localhost.localdomain.pid
datadir=/var/lib/mysql/
user=root
[mysqld3307]
port=3307
socket=/home/fuyouling/mutl_mysql/mysql_3307/mysql/mysql.sock
pid-file=/home/fuyouling/mutl_mysql/mysql_3307/mysql/localhost.localdomain.pid
datadir=/home/fuyouling/mutl_mysql/mysql_3307/mysql/
user=root
15.启动新实例
mysqld_multi --defaults-extra-file=/usr/my.cnf start 3307
16.检查新实例是否生成
netstat -nltp或者ps -ef|grep mysql 查看是否有两个mysql端口或进程
也可以mysqld_multi report(这种方式不是很保险)
17.设置新实例密码
mysqladmin -uroot password ‘654321‘ -S /home/fuyouling/mutl_mysql/mysql_3307/mysql/mysql.sock
18.登录新实例
mysql -uroot -p654321 -S /home/fuyouling/mutl_mysql/mysql_3307/mysql/mysql.sock
19.检查新实例是否使用新的数据文件目录
show variables like ‘%datadir%‘
20.关闭新实例
mysqladmin -uroot -p654321 -S /home/fuyouling/mutl_mysql/mysql_3307/mysql/mysql.sock shutdown
21.检查新实例是否关闭成功
netstat -nltp或者ps -ef|grep mysql
原文:http://quguanhai.blog.51cto.com/1951497/1793883