mysql5.6.20二进制安装部署文档
一、业务需求:
单台服务器线上运行着mysql5.5.48
现在是不影响线上的业务,不停止线上的mysql5.5数据库来部署另外一个mysql5.6.20的实例
二、安装部署过程:
2.1安装部署过程注意事项:
在初始化mysql数据库时,是会寻找my.cnf配置文件的,是有顺序的,默认的顺序是:
[root@localhost ~]# mysql --help | grep 'Default options' -A 1
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf
查看当前mysql运行采用的是哪个配置文件:
[root@localhost ~]# cat /proc/$(pidof mysqld)/cmdline | tr '\0' '\n'
/usr/local/mysql5.6/bin/mysqld
--defaults-file=/usr/local/mysql5.6/my.cnf
--basedir=/usr/local/mysql5.6
--datadir=/data/mysql3307/data
--plugin-dir=/usr/local/mysql5.6/lib/plugin
--user=mysql
--log-error=/data/mysql3307/log/error.log
--open-files-limit=65535
--pid-file=/data/mysql3307/log/git-server.pid
--socket=/tmp/mysql3307.sock
--port=3307
提示:上面的命令只适合查看单实例mysql
参考:https://www.electrictoolbox.com/mysql-my-cnf/
https://www.psce.com/en/blog/2012/04/01/how-to-find-mysql-configuration-file/
2.2开始部署:
注意:要把现在线上运行的mysql5.5.48采用的my.cnf配置文件mv为另外一个名称,否则在初始化mysql5.6的时候会报错。原因是:初始化mysql5.6时,默认是先寻找/etc/my.cnf这个文件的。但是这个文件正在被mysql5.5.48在采用,所以要把这个文件改名,然后把mysql5.6.20的my.cnf的配置文件移到/usr/local/mysql5.6/下面,然后在初始化mysql5.6.20
mv /etc/my.cnf /etc/my.cnf.bak
如果不把线上mysql5.5.48的my.cnf配置文件改名的话,初始化mysql5.6.20会报如下错误:
[root@localhost scripts]# ./mysql_install_db --datadir=/data/mysql3307/data --basedir=/usr/local/mysql5.6 --user=mysql --explicit_defaults_for_timestamp
Installing MySQL system tables...2017-08-27 14:04:28 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2017-08-27 14:04:28 0 [Note] /usr/local/mysql5.6/bin/mysqld (mysqld 5.6.36-log) starting as process 7379 ...
2017-08-27 14:04:28 7379 [Note] InnoDB: Using atomics to ref count buffer pool pages
2017-08-27 14:04:28 7379 [Note] InnoDB: The InnoDB memory heap is disabled
2017-08-27 14:04:28 7379 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2017-08-27 14:04:28 7379 [Note] InnoDB: Memory barrier is not used
2017-08-27 14:04:28 7379 [Note] InnoDB: Compressed tables use zlib 1.2.3
2017-08-27 14:04:28 7379 [Note] InnoDB: Using Linux native AIO
2017-08-27 14:04:28 7379 [Note] InnoDB: Using CPU crc32 instructions
2017-08-27 14:04:28 7379 [Note] InnoDB: Initializing buffer pool, size = 1.0G
2017-08-27 14:04:28 7379 [Note] InnoDB: Completed initialization of buffer pool
2017-08-27 14:04:28 7379 [ERROR] InnoDB: Unable to lock /usr/local/mysql/var/ibdata1, error: 11
2017-08-27 14:04:28 7379 [Note] InnoDB: Check that you do not already have another mysqld process using the same InnoDB data or log files.
2017-08-27 14:04:28 7379 [Note] InnoDB: Retrying to lock the first data file
2017-08-27 14:04:29 7379 [ERROR] InnoDB: Unable to lock /usr/local/mysql/var/ibdata1, error: 11
2017-08-27 14:04:29 7379 [Note] InnoDB: Check that you do not already have another mysqld process using the same InnoDB data or log files.
2017-08-27 14:04:30 7379 [ERROR] InnoDB: Unable to lock /usr/local/mysql/var/ibdata1, error: 11
2017-08-27 14:04:30 7379 [Note] InnoDB: Check that you do not already have another mysqld process using the same InnoDB data or log files.
2017-08-27 14:04:31 7379 [ERROR] InnoDB: Unable to lock /usr/local/mysql/var/ibdata1, error: 11
2017-08-27 14:04:31 7379 [Note] InnoDB: Check that you do not already have another mysqld process using the same InnoDB data or log files.
2017-08-27 14:04:32 7379 [ERROR] InnoDB: Unable to lock /usr/local/mysql/var/ibdata1, error: 11
2017-08-27 14:04:32 7379 [Note] InnoDB: Check that you do not already have another mysqld process using the same InnoDB data or log files.
2017-08-27 14:04:33 7379 [ERROR] InnoDB: Unable to lock /usr/local/mysql/var/ibdata1, error: 11
2017-08-27 14:04:33 7379 [Note] InnoDB: Check that you do not already have another mysqld process using the same InnoDB data or log files.
所以要先把线上的mysql5.5.48的my.cnf配置文件改名(切记此期间不要对mysql5.5.48有任何的修改启动服务操作),等mysql5.6.20成功部署好后记得再把改名后的mysql5.5.48的配置文件改回原来的/etc/my.cnf
Mysql二进制包下载地址
useradd mysql
mkdir /data1/mysql5.6/{data,var} -p
chown -R mysql.mysql /data1/mysql5.6/
tar xf /tmp/mysql-5.6.20-linux-glibc2.5-x86_64.tar.gz -C /usr/local/
cd /usr/local/
mv mysql-5.6.20-linux-glibc2.5-x86_64 mysql5.6
chown -R mysql.mysql /usr/local/mysql5.6
cp my.cnf(mysql5.6.20的配置文件) /usr/local/mysql5.6/
cd /usr/local/mysql5.6/scripts
[root@localhost scripts]# ./mysql_install_db --datadir=/data/mysql5.6/data --basedir=/usr/local/mysql5.6 --user=mysql --explicit_defaults_for_timestamp
Installing MySQL system tables.../usr/local/mysql/bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
解决:
yum -y install libaio-devel 或者yum install libaio*
./mysql_install_db --datadir=/data1/mysql5.6/data --basedir=/usr/local/mysql5.6 --user=mysql --explicit_defaults_for_timestamp
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql5.6
sed -i 's#/usr/local/mysql5.6#/usr/local/mysql#g' /etc/init.d/mysql5.6
chkconfig mysql5.6 on
echo "export PATH=$PATH:/usr/local/mysql5.6/bin" > /etc/profile.d/mysql.sh
source /etc/profile
2.3启动mysql5.6.20设置密码:
第一种方式启动mysql
/etc/init.d/mysql5.6 start
第二种方式启动mysql
mysqld_safe --defaults-file=/usr/local/mysql5.6/my.cnf &
ps -ef|grep mysql
给mysql5.6.20设置密码:
/usr/local/mysql5.6/bin/mysqladmin -u root password 'Zydfg55726' -S /tmp/mysql3307.sock
mysql -uroot -p -S /tmp/mysql3307.sock
平滑关闭mysql5.6.20:
mysqladmin -uroot -p'Zydfg55726' -S /tmp/mysql3307.sock shutdown
/etc/init.d/mysql5.6 stop
2.4 mysql5.6.20的my.cnf配置文件:
[root@localhost ~]# cat /etc/my.cnf
[client]
#password= your_password
port= 3307
socket= /tmp/mysql3307.sock
[mysqld]
port= 3307
socket= /tmp/mysql3307.sock
datadir = /data1/mysql5.6/data
skip-external-locking
key_buffer_size = 32M
max_allowed_packet = 50M
table_open_cache = 1024
sort_buffer_size = 4M
net_buffer_length = 8K
read_buffer_size = 4M
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 64M
thread_cache_size = 128
#query_cache_size = 128M
tmp_table_size = 64M
max_join_size=3G
#skip-networking
skip-name-resolve
max_connections = 500
max_connect_errors = 1000
open_files_limit = 65535
#log-bin=mysql-bin
#binlog_format=row
server-id= 1
#expire_logs_days = 1
#default_storage_engine = InnoDB
innodb_data_home_dir = /data1/mysql5.6/var
innodb_data_file_path = ibdata1:300M:autoextend
innodb_log_group_home_dir = /data1/mysql5.6/var
innodb_buffer_pool_size = 1024M
innodb_additional_mem_pool_size = 2M
innodb_log_file_size = 256M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 0
innodb_lock_wait_timeout = 50
#innodb_force_recovery = 2
[mysqldump]
quick
max_allowed_packet = 256M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 16M
sort_buffer_size = 4M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
到此单台服务器上开启另外一个实例mysql5.6.20成功完成。而且不会对线上mysql5.5.48的业务产生任何影响的