mysql5.6源码安装两个实例--模拟生产库
源码方式---安装两个实例(mysql5.6.40&CentOS6.8)----------生产库
mysql源码包:mysql-5.6.40.tar.gz
安装相关软件(前提条件是yum已正常使用)
# yum -y install make cmake gcc gcc-c++ bison-devel ncurses-devel libaio libaio-devel perl-Data-Dumper net-tools
停用系统防火墙和selinux
# service iptables stop
# service ip6tables stop
# chkconfig iptables off
# chkconfig ip6tables off
# vi /etc/selinux/config
将SELINUX=enforcing这个值改为SELINUX=disabled
创建用户和组
# groupadd mysql
# useradd -g mysql mysql
创建目录
目录说明:
软件目录:/u01/svr/mysql5.6
数据库目录:/u01/mydata/{my3306,my3307}
log目录:/u01/logs
配置文件目录:/u01/conf
mkdir -p /u01/{svr,logs,conf,mydata,tmp,run}
mkdir -p /u01/svr/mysql5.6
mkdir -p /u01/mydata/{my3306,my3307}
mkdir -p /u01/logs/{my3306,my3307}/{binlog,iblog}
mkdir -p /u01/tmp/{my3306,my3307}
chown -R mysql:mysql /u01/
chmod -R 755 /u01/
查看是否安装了mysql
# rpm -qa|grep mysql -i
如果存在需要卸载,不然下面的安装有可能会冲突
# rpm -e --nodeps xxx (xxx搜索的结果)
上传源码安装包到/u01下并解压到前目录:tar -zxvf /u01/mysql-5.6.40.tar.gz
cd /u01//mysql-5.6.40
预编译
# cmake \
-DCMAKE_INSTALL_PREFIX=/u01/svr/mysql5.6 \
-DMYSQL_DATADIR=/u01/mydata/my3306 \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/u01/run/mysql3306.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
执行完后最后会有下面的信息
strict-aliasing -DDBUG_OFF
-- Configuring done
-- Generating done
CMake Warning:
Manually-specified variables were not used by the project:
WITH_MEMORY_STORAGE_ENGINE
WITH_READLINE
-- Build files have been written to: /home/temp/mysql-5.6.40
然后进行编译
# make && make install
因编译后有些文件的权限是root的,需要重新授权
chown -R mysql:mysql /u01/
chmod -R 755 /u01/
实例一:3306配置文件
# vi /u01/conf/my3306.cnf
[client]
port=3306
socket=/u01/run/mysql3306.sock
[mysql]
pid_file=/u01/run/mysqld3306.pid
[mysqld]
autocommit=1
general_log=off
explicit_defaults_for_timestamp=true
# system
basedir=/u01/svr/mysql5.6
datadir=/u01/mydata/my3306
max_allowed_packet=1g
max_connections=3000
max_user_connections=2800
open_files_limit=65535
pid_file=/u01/run/mysqld3306.pid
port=3306
server_id=101
skip_name_resolve=ON
socket=/u01/run/mysql3306.sock
tmpdir=/u01/tmp/my3306
#binlog
log_bin=/u01/logs/my3306/binlog
binlog_cache_size=32768
binlog_format=row
expire_logs_days=7
log_slave_updates=ON
max_binlog_cache_size=2147483648
max_binlog_size=524288000
sync_binlog=100
#logging
log_error=/u01/logs/my3306/error.log
slow_query_log_file=/u01/logs/my3306/slow.log
log_queries_not_using_indexes=0
slow_query_log=1
log_slave_updates=ON
log_slow_admin_statements=1
long_query_time=1
#relay
relay_log=/u01/logs/my3306/relaylog
relay_log_index=/u01/logs/my3306/relay.index
relay_log_info_file=/u01/logs/my3306/relay-log.info
#slave
slave_load_tmpdir=/u01/tmp/my3306/
slave_skip_errors=OFF
#innodb
innodb_data_home_dir=/u01/logs/my3306/iblog/
innodb_log_group_home_dir=/u01/logs/my3306/iblog/
innodb_adaptive_flushing=ON
innodb_adaptive_hash_index=ON
innodb_autoinc_lock_mode=1
innodb_buffer_pool_instances=8
#default
innodb_change_buffering=inserts
innodb_checksums=ON
innodb_buffer_pool_size= 128M
innodb_data_file_path=ibdata1:32M;ibdata2:16M:autoextend
innodb_doublewrite=ON
innodb_file_format=Barracuda
innodb_file_per_table=ON
innodb_flush_log_at_trx_commit=1
innodb_flush_method=O_DIRECT
innodb_io_capacity=1000
innodb_lock_wait_timeout=10
innodb_log_buffer_size=67108864
innodb_log_file_size=1048576000
innodb_log_files_in_group=4
innodb_max_dirty_pages_pct=60
innodb_open_files=60000
innodb_purge_threads=1
innodb_read_io_threads=4
innodb_stats_on_metadata=OFF
innodb_support_xa=ON
innodb_use_native_aio=OFF
innodb_write_io_threads=10
[mysqld_safe]
datadir=/u01/mydata/my3306/
实例二:3307配置文件
# vi /u01/conf/my3307.cnf
[client]
port=3307
socket=/u01/run/mysql3307.sock
[mysql]
pid_file=/u01/run/mysqld3307.pid
[mysqld]
autocommit=1
general_log=off
explicit_defaults_for_timestamp=true
# system
basedir=/u01/svr/mysql5.6
datadir=/u01/mydata/my3307
max_allowed_packet=1g
max_connections=3000
max_user_connections=2800
open_files_limit=65535
pid_file=/u01/run/mysqld3307.pid
port=3307
server_id=102
skip_name_resolve=ON
socket=/u01/run/mysql3307.sock
tmpdir=/u01/tmp/my3307
#binlog
log_bin=/u01/logs/my3307/binlog
binlog_cache_size=32768
binlog_format=row
expire_logs_days=7
log_slave_updates=ON
max_binlog_cache_size=2147483648
max_binlog_size=524288000
sync_binlog=100
#logging
log_error=/u01/logs/my3307/error.log
slow_query_log_file=/u01/logs/my3307/slow.log
log_queries_not_using_indexes=0
slow_query_log=1
log_slave_updates=ON
log_slow_admin_statements=1
long_query_time=1
#relay
relay_log=/u01/logs/my3307/relaylog
relay_log_index=/u01/logs/my3307/relay.index
relay_log_info_file=/u01/logs/my3307/relay-log.info
#slave
slave_load_tmpdir=/u01/tmp/my3307/
slave_skip_errors=OFF
#innodb
innodb_data_home_dir=/u01/logs/my3307/iblog/
innodb_log_group_home_dir=/u01/logs/my3307/iblog/
innodb_adaptive_flushing=ON
innodb_adaptive_hash_index=ON
innodb_autoinc_lock_mode=1
innodb_buffer_pool_instances=8
#default
innodb_change_buffering=inserts
innodb_checksums=ON
innodb_buffer_pool_size= 128M
innodb_data_file_path=ibdata1:32M;ibdata2:16M:autoextend
innodb_doublewrite=ON
innodb_file_format=Barracuda
innodb_file_per_table=ON
innodb_flush_log_at_trx_commit=1
innodb_flush_method=O_DIRECT
innodb_io_capacity=1000
innodb_lock_wait_timeout=10
innodb_log_buffer_size=67108864
innodb_log_file_size=1048576000
innodb_log_files_in_group=4
innodb_max_dirty_pages_pct=60
innodb_open_files=60000
innodb_purge_threads=1
innodb_read_io_threads=4
innodb_stats_on_metadata=OFF
innodb_support_xa=ON
innodb_use_native_aio=OFF
innodb_write_io_threads=10
[mysqld_safe]
datadir=/u01/mydata/my3307/
注:两个实例的server_id不能一样!!
初始化3306数据库
# cd /u01/svr/mysql5.6/scripts
# ./mysql_install_db --basedir=/u01/svr/mysql5.6 --datadir=/u01/mydata/my3306 --defaults-file=/u01/conf/my3306.cnf
初始化3307数据库
# cd /u01/svr/mysql5.6/scripts
# ./mysql_install_db --basedir=/u01/svr/mysql5.6 --datadir=/u01/mydata/my3307 --defaults-file=/u01/conf/my3307.cnf
查看
/u01/logs/my3306/erro.log和/u01/logs/my3307/erro.log
是否有报错信息,重点查看erro关键词,如没有证明成功安装。
如果报错,需要把data和log新生成的文件删除再重新执行初始化
设置环境变量
在PATH=$PATH:$HOME/bin添加参数:/u01/svr/mysql5.6/bin:/u01/svr/mysql5.6l/lib
$ vi /home/mysql/.bash_profile
PATH=$PATH:$HOME/bin:/u01/svr/mysql5.6/bin:/u01/svr/mysql5.6l/lib
$ source /home/mysql/.bash_profile
接下来就是启动、使用、关闭mysql两个实例,创建sh文件夹存放sh脚本
$ mkdir /u01/sh
注:多个实例,建议分开启动,这样便于管理
创建启动脚本
$ vi /u01/sh/start3306.sh
#!/bin/bash
mysqld_safe --defaults-file=/u01/conf/my3306.cnf --socket=/u01/run/mysql3306.sock &
$ vi /u01/sh/start3307.sh
#!/bin/bash
mysqld_safe --defaults-file=/u01/conf/my3307.cnf --socket=/u01/run/mysql3307.sock &
授权
$ chmod +x *.sh
启动和查看进程
$ ps -ef|grep mysql
注意是否有/bin/sh /u01/svr/mysql5.6/bin/mysqld_safe和/u01/svr/mysql5.6/bin/mysqld这两种进程,每个实例有两个进程
注: 建议使用mysqld_safe启动mysql,mysqld_safe会一直监控着,如果mysqld服务异常的关闭了,mysqld_safe会自动启动mysqld服务
修改密码
登录脚本有可能需要修改root用户后才正常,启动服务后,更改root密码
$ mysql
mysql> update mysql.user set Password = password('新密码') where User='root';
如:update mysql.user set Password = password('root') where User='root';
mysql> flush privileges;
创建登录mysql脚本
$ vi /u01/sh/m6
#!/bin/bash
mysql --socket=/u01/run/mysql3306.sock --port=3306 -p
$ vi /u01/sh/m7
#!/bin/bash
mysql --socket=/u01/run/mysql3307.sock --port=3307 -p
授权
$ chmod +x *
创建关闭脚本
$ vi /u01/sh/shutdown3306.sh
#!/bin/bash
mysqladmin --socket=/u01/run/mysql3306.sock --port=3306 shutdown -p
$ vi /u01/sh/shutdown3307.sh
#!/bin/bash
mysqladmin --socket=/u01/run/mysql3307.sock --port=3307 -p shutdown -p
授权
$ chmod +x *.sh
//为root添加远程连接的能力。
mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "新密码";