1. 程式人生 > >mysql5.6.20二進制安裝部署文檔

mysql5.6.20二進制安裝部署文檔

mysql 二進制 安裝部署

mysql5.6.20二進制安裝部署文檔


一、業務需求:

單臺服務器線上運行著mysql5.5.48

現在是不影響線上的業務,不停止線上的mysql5.5數據庫來部署另外一個mysql5.6.20的實例


二、安裝部署過程:

2.1安裝部署過程註意事項:

在初始化mysql數據庫時,是會尋找my.cnf配置文件的,是有順序的,默認的順序是:

[[email protected] ~]# 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運行采用的是哪個配置文件:

[[email protected] ~]# 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會報如下錯誤:


[[email protected] 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二進制包下載地址

http://ftp.ntu.edu.tw/MySQL/Downloads/MySQL-5.6/


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

[[email protected] 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配置文件:

[[email protected] ~]# 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的業務產生任何影響的

本文出自 “10931853” 博客,請務必保留此出處http://wujianwei.blog.51cto.com/10931853/1959711

mysql5.6.20二進制安裝部署文檔