linux上安装多个不同版本的mysql踩的坑
最近由于业务需要,考虑使⽤json类型,据了解mysql在版本5.7中可以⽀持json类型的数据⽀持,但同时⽬前开发环境中使⽤的是mysql 5.6版本,上⾯还有很多项⽬的数据库在上⾯,同时也没有多余的服务器可供使⽤,故不能直接卸载将mysql直接升级版本。
从⽽想到在同⼀台机器上安装多个版本的mysql来解决问题。
上⾯说到之前环境已经装有mysql 5.6版本,基本配置如下:
datadir=/home/mysql/data
basedir=/usr/local/mysql
同时配置⽂件myf放在在/etc/⽬录下。
此版本是通过yum的⽅式来下载安装的,故5.7的版本不能再使⽤这种⽅式安装,以免数据被覆盖。
我的系统版本是centos 64位,故在官⽹下载 5.7 64版本的安装包。()
具体操作如下:
mkdir /usr/local/app
cd /usr/local/app
wget -o sql/archives/get/file/mysql-5.7.24-linux-glibc2.12-x86_
tar -xzf mysql-5.7.24-linux-glibc2.12-x86_
mv mysql-5.7.24-linux-glibc2.12-x86_64 mysql-5.7.24
mv mysql-5.7.24 ../
cd ../mysql-5.7.24
此时已将mysql 5.7 解压出来。这个版本的mysql已经不包含模板配置⽂件。此时初始化数据库(先授权,由于之前已经创建了mysql:mysql 的⽤户组及⽤户了,但还没有5.7版本⽬录和数据的权限):
mkdir /home/mysql-5.7.24/data
chown mysql:mysql -R  /home/mysql-5.7.24/data /usr/local/mysql-5.7.24
.
/bin/mysqld --initialize --user=mysql --datadir=/home/mysql-5.7.24/data --basedir=/usr/local/mysql-5.7.24
此时会⽣成默认的root密码,记下来。
然后再使⽤mysqld_multi来管理多实例。原本我是想直接使⽤support-files⽬录下mysql_server来启动的,但是发现个问题,就是该脚本总是使⽤/etc/myf作为配置⽂件来启动的,于是我查了下资料,发现mysql读写配置顺序如下:
/etc/myf > /etc/mysql/myf > /usr/etc/myf > ~/.myf
由于该配置⽂件已被 5.6 版本的mysql使⽤,故寻其他⽅法。
⽅法⼀
使⽤mysqld_multi来管理。
修改/etc/myf:
#[client]
#port = 3306
#socket = /usr/local/mysql/mysql.sock
[mysqld_multi]
mysqld = /usr/local/mysql-5.7.24/bin/mysqld_safe
log = /var/log/mysqld_multi.log
[mysqld3306]
user=mysql
server_id=206
port = 3306
basedir = /usr/local/mysql
datadir = /home/mysql/data
tmpdir = /home/mysql/temp
socket = /usr/local/mysql/mysql.sock
log-error = /home/mysql/logs/mysql_error.log
pid-file = /home/mysql/mysql.pid
slow-query-log-file = /home/mysql/logs/mysql-slow.log
[mysqld3307]
user=mysql
server_id=207
port = 3307
basedir = /usr/local/mysql-5.7.24
datadir = /home/mysql-5.7.24/data
tmpdir = /home/mysql-5.7.24/temp
socket = /usr/local/mysql-5.7.24/mysql.sock
log-error = /home/mysql-5.7.24/logs/mysql_error.log
pid-file = /home/mysql-5.7.24/mysql.pid
slow-query-log-file = /home/mysql-5.7.24/logs/mysql-slow.log
mysql下载什么版本的
[mysqld]
#server_id=206
#binlog-do-db=testdb
binlog-ignore-db=mysql
log-bin=edu-mysql-slave1-bin
binlog_cache_size = 1M
binlog_format=mixed
expire_logs_days=7
slave_skip_errors=1062
relay_log=edu-mysql-relay-bin
log_slave_updates=1
read_only=0
character-set-server = utf8
collation-server = utf8_general_ci
skip-external-locking
skip-name-resolve
#user = mysql
#port = 3306
#basedir = /usr/local/mysql
#datadir = /home/mysql/data
#tmpdir = /home/mysql/temp
# server_id = .....
#socket = /usr/local/mysql/mysql.sock
#log-error = /home/mysql/logs/mysql_error.log
#pid-file = /home/mysql/mysql.pid
open_files_limit = 10240
back_log = 600
max_connections=500
max_connect_errors = 6000
wait_timeout=605800
#open_tables = 600
#table_cache = 650
#opened_tables = 630
max_allowed_packet = 32M
sort_buffer_size = 4M
join_buffer_size = 4M
thread_cache_size = 300
query_cache_type = 1
query_cache_size = 256M
query_cache_limit = 2M
query_cache_min_res_unit = 16k
tmp_table_size = 256M
max_heap_table_size = 256M
key_buffer_size = 256M
read_buffer_size = 1M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 64M
lower_case_table_names=1
default-storage-engine = INNODB
innodb_buffer_pool_size = 2G
innodb_log_buffer_size = 32M
innodb_log_file_size = 128M
innodb_flush_method = O_DIRECT
>>>>#
#thread_concurrency = 32
long_query_time= 2
slow-query-log = on
#slow-query-log-file = /home/mysql/logs/mysql-slow.log [mysqld-5.7]
innodb_buffer_pool_dump_pct = 40
innodb_page_cleaners = 4
innodb_undo_log_truncate = 1
innodb_max_undo_log_size = 1G
innodb_purge_rseg_truncate_frequency = 128
binlog_gtid_simple_recovery=1
log_timestamps=system
transaction_write_set_extraction=MURMUR32
show_compatibility_56=on
[mysqldump]
quick
max_allowed_packet = 32M
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
上⾯多余的配置根据需求可以去掉,保留关键的配置即可,主要是端⼝,pid,和⽂件路径这些要不⼀样。
修改完成后,可以使⽤support_files⽬录下的mysqld_multi.server来管理多个版本实例了。
./mysqld_multi.server有start,stop,report⼏个操作,顾名思义,使⽤就好了,report就是类似status的意思。
./mysqld_multi.server report
发现
MySQL server from group: mysqld3306 is running
MySQL server from group: mysqld3307 is not running
然后启动3307即可,
./mysqld_multi.server start 3307
MySQL server from group: mysqld3306 is running
MySQL server from group: mysqld3307 is running
不指定某个具体的实例就是启动或者关闭所有的。
这样就搞定了,但在终端使⽤客户端的时候要注意要具体指定某⼀个sock⽂件和端⼝:
mysql -S /usr/local/mysql-5.7.24/mysql.sock -P 3307 -u root -p
最后,可以将mysqld_multi作为系统服务:
cp /usr/local/mysql-5.7.24/support-files/mysqld_multi.server /etc/rc.d/init.d/mysqld_multi
chkconfig --add /mysqld_multi
就可以直接使⽤了:
mysqld_multi report
⽅法⼆
使⽤bin/mysqld_safe指定配置⽂件来启动:
cp /etc/myf ./
##改改其中的⼀些配置(端⼝,pid,和⽂件路径)
./bin/mysqld_safe –defaults-file=/usr/local/mysql-5.7.24/myf –basedir=/usr/local/mysql-5.7.24 –datadir=/home/mysql-5.7.24/data & ⽂章有些杂乱,有时间再优化。

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。

发表评论