MYSQL单机多实例

1.解压包到/usr/local

#cd  /usr/local

#tar zxvf mysql-5.6.31-linux-glibc2.5-x86_64.tar.gz 
 

2.重命名

#mv mysql-5.6.31-linux-glibc2.5-x86_64 mysql3306
#cp -rp mysql3306 mysql3307
 

3.增加mysql用户

#groupadd mysql

#useradd -r -g mysql mysql
 

4.分别初始化

#scripts/mysql_install_db --user=mysql  --basedir=/usr/local/mysql3306  --datadir=/usr/local/mysql3306/data
#scripts/mysql_install_db --user=mysql  --basedir=/usr/local/mysql3307  --datadir=/usr/local/mysql3307/data

报错解决:

 yum install libaio-devel

yum install perl-Data-Dumper.x86_64

 
5.修改my.cnf

 

[root@localhost mysql3307]# cat my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html

[mysqld]
basedir=/usr/local/mysql3307
datadir=/usr/local/mysql3307/data
pid-file=/usr/local/mysql3307/data/mysql3307.pid
port=3307
server_id=2
socket=/tmp/mysql3307.sock
character-set-server=utf8mb4
init_connect='SET NAMES utf8mb4'

[client]
default-character-set=utf8mb4

[mysql]
default-character-set=utf8mb4



6.启动mysql
#bin/mysqld_safe --defaults-file=/usr/local/mysql3306/my.cnf  --user=mysql  
#bin/mysqld_safe --defaults-file=/usr/local/msyql3307/my.cnf  --user=mysql  

7.将第6步的命令写入/etc/rc.d/rc.local中

8.本地访问不同的mysql服务
mysql -uroot  -S /tmp/mysql3306.sock 
mysql -uroot  -S /tmp/mysql3307.sock

你可能感兴趣的:(mysql)