Mysql多实例安装笔记

参考:
系统:KaliLinux (x86_64)

软件下载

1、下载地址:
2、选择5.6版本

安装

1、准备文件和目录

tar -zxvf mysql-5.6.40-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
cd /usr/local/
ln -sv mysql-5.6.40-linux-glibc2.12-x86_64 mysql

mkdir -pv /data/mysql_3306
mkdir -pv /data/mysql_3307
mkdir -pv /data/mysql_3306/{data,log}
mkdir -pv /data/mysql_3307/{data,log}

2、修改权限

chown -R mysql.mysql /usr/local/mysql
chown -R mysql.mysql /data

3、初始化数据

/usr/local/mysql/scripts/mysql_install_db --datadir=/data/mysql_3306/data --user=mysql --basedir=/usr/local/mysql --no-defaults
/usr/local/mysql/scripts/mysql_install_db --datadir=/data/mysql_3307/data --user=mysql --basedir=/usr/local/mysql --no-defaults

4、配置文件

  • /etc/my3306.cnf
[client]
user=root
port=3306  
socket=/tmp/mysql.sock  
 
[mysqld] 
user=mysql  
basedir = /usr/local/mysql  
datadir=/data/mysql_3306/data
pid-file=/data/mysql_3306/data/mysql_3306.pid
port=3306  
server_id=3306  
socket=/tmp/mysql_3306.sock  
character_set_server = utf8
skip_name_resolve = 1
max_connections = 800
max_connect_errors = 1000
max_allowed_packet = 16777216  
log-error = /data/mysql_3306/log/error.log  
binlog_format = mixed  
expire_logs_days = 30
log-bin = /data/mysql_3306/log/mysql-bin.log  
log-bin-index = /data/mysql_3306/log/mysql-bin.index
  • /etc/my3307.cnf
[client]
root=root
port=3307
socket=/tmp/mysql.sock  
 
[mysqld] 
user=mysql  
basedir = /usr/local/mysql  
datadir=/data/mysql_3307/data
pid-file=/data/mysql_3307/data/mysql_3307.pid
port=3307  
server_id=3307  
socket=/tmp/mysql_3307.sock  
character_set_server = utf8
skip_name_resolve = 1
max_connections = 800
max_connect_errors = 1000
max_allowed_packet = 16777216
log-error = /data/mysql_3307/log/error.log  
binlog_format = mixed  
expire_logs_days = 30
log-bin = /data/mysql_3307/log/mysql-bin.log  
log-bin-index = /data/mysql_3307/log/mysql-bin.index

5、启动服务

/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my3306.cnf &
/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my3306.cnf &

6、连接服务

mysql -S /tmp/mysql_3306.sock
mysql -S /tmp/mysql_3307.sock
或
/usr/local/mysql/bin/mysql -h 127.0.0.1 -P3306
/usr/local/mysql/bin/mysql -h 127.0.0.1 -P3307
posted @ 2018-04-25 18:10  懒企鹅  阅读(269)  评论(0编辑  收藏  举报