三、安装配置多实例MYSQL5.6-多独立配置文件方法

三、安装配置多实例MYSQL5.6-多独立配置文件方法

1、准备工作

检查操作系统版本、内核版本、selinux是否关闭、防火墙策略、IP地址、主机名配置、host表配置、yum配置

上传cmakemysql5.6软件包

具体步骤参考源码安装mysql-单实例配置文档

 

2、安装cmake软件

2.1 安装编译软件环境

[root@centos6 ~]# yum -y install gcc-c++ncurses-devel make perl bison ncurses

2.2 解压软件包

[root@centos6 ~]# cd /opt/software/

[root@centos6 software]# tar -zxfcmake-3.0.1.tar.gz

2.3 编译安装

[root@centos6 cmake-3.0.1]# pwd

/opt/software/cmake-3.0.1

[root@centos6 cmake-3.0.1]# ./bootstrap

[root@centos6 cmake-3.0.1]# gmake&& make install

2.4 校验安装是否成功

[root@mysql ~]# cmake --version

[root@centos6 cmake-3.0.1]# cmake --version

cmake version 3.0.1

 

3、安装mysql

3.1 创建mysql用户、用户组

[root@centos6 cmake-3.0.1]# useradd mysql-s '/sbin/nologin' -r �CM //-r创建系统用户,-M不创建home目录

[root@centos6 cmake-3.0.1]# id mysql

uid=498(mysql) gid=498(mysql)groups=498(mysql)

3.2 创建mysql安装目录

[root@centos6 ~]# mkdir /usr/local/mysql

3.3 创建mysql数据目录

[root@centos6 ~]# mkdir -pv/home/mysql/data{3306,3307}

mkdir: created directory `/home/mysql'

mkdir: created directory`/home/mysql/data3306'

mkdir: created directory`/home/mysql/data3307'

[root@centos6 ~]# tree /home/mysql/

/home/mysql/

├── data3306

└── data3307

 

2 directories, 0 files

[root@centos6 ~]#

 

3.5 编译安装mysql5.6

[root@centos6 ~]# cd /opt/software

[root@centos6 software]# tar -zxfmysql-5.6.16.tar.gz

[root@centos6 software]# cd mysql-5.6.16

 

[root@centos6 mysql-5.6.16]# cmake \

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \

-DMYSQL_DATADIR=/home/mysql/ \

-DSYSCONFDIR=/etc \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_ARCHIVE_STORAGE_ENGINE=1 \

-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \

-DENABLED_LOCAL_INFILE=1 \

-DWITH_PARTITION_STORAGE_ENGINE=1 \

-DEXTRA_CHARSETS=all \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci \

-DWITH_EXTRA_CHARSETS:STRING=utf8,gbk

 

[root@centos6 mysql-5.6.16]# make&& make install

 

4、配置3306数据库主配置文件

[root@centos6 ~]# cd /home/mysql/data3306

[root@centos6 data3306]# vim my.cnf

[client] 

socket = /home/mysql/data3306/mysqld.sock 

port = 3306  

 

[mysqld] 

basedir =/usr/local/mysql 

datadir =/home/mysql/data3306 

socket = /home/mysql/data3306/mysqld.sock 

port =3306 

server_id =1

user = mysql 

join_buffer_size = 128M 

sort_buffer_size = 2M 

read_rnd_buffer_size = 2M 

default_storage_engine = InnoDB

join_buffer_size = 128M 

max_allowed_packet= 1M 

net_buffer_length= 8K 

  

skip-external-locking 

skip-host-cache 

skip-name-resolve 

 

# InnoDB 

innodb_buffer_pool_size = 128M 

innodb_log_file_size = 48M 

innodb_file_per_table = 1 

innodb_flush_method = O_DIRECT 

       

# MyISAM 

key_buffer_size = 48M 

character-set-server=utf8 

collation-server=utf8_general_ci 

         

# LOG 

log_error = /home/mysql/data3306/mysql-error.log 

long_query_time = 1 

slow-query-log 

slow_query_log_file = /home/mysql/data3306/mysql-slow.log 

                

# Others 

explicit_defaults_for_timestamp=true 

max_connections = 500 

open_files_limit = 65535 

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

 

5、配置3307数据库主配置文件

[root@centos6 data3306]# cp my.cnf../data3307/

[root@centos6 data3306]# sed -i's/3306/3307/g' ../data3307/my.cnf

[root@centos6 data3306]# vim../data3307/my.cnf

server_id =2

[root@centos6 data3306]# cat ../data3307/my.cnf

[client] 

socket =/home/mysql/data3307/mysqld.sock 

port = 3307 

 

[mysqld] 

basedir =/usr/local/mysql 

datadir =/home/mysql/data3307  

socket = /home/mysql/data3307/mysqld.sock 

port =3307  

server_id =2

user = mysql 

join_buffer_size = 128M 

sort_buffer_size = 2M 

read_rnd_buffer_size = 2M 

default_storage_engine = InnoDB

join_buffer_size = 128M 

max_allowed_packet= 1M 

net_buffer_length= 8K 

  

skip-external-locking 

skip-host-cache 

skip-name-resolve 

 

# InnoDB 

innodb_buffer_pool_size = 128M 

innodb_log_file_size = 48M 

innodb_file_per_table = 1 

innodb_flush_method = O_DIRECT 

       

# MyISAM 

key_buffer_size = 48M 

character-set-server=utf8 

collation-server=utf8_general_ci 

         

# LOG 

log_error = /home/mysql/data3307/mysql-error.log 

long_query_time = 1 

slow-query-log 

slow_query_log_file = /home/mysql/data3307/mysql-slow.log 

                

# Others 

explicit_defaults_for_timestamp=true 

max_connections = 500 

open_files_limit = 65535 

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

 

[root@centos6 data3306]#

 

6、改变数据目录的属主

[root@centos6 ~]# chown -R mysql.mysql/home/mysql/data330{6,7}

[root@centos6 ~]# ls -ld /home/mysql/data330{6,7}

drwxr-xr-x 2 mysql mysql 4096 Nov  6 18:54 /home/mysql/data3306

drwxr-xr-x 2 mysql mysql 4096 Nov  6 18:54 /home/mysql/data3307

 

7、配置环境变量

[root@centos6 ~]# echo $PATH

/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

[root@centos6 ~]# echo 'exportPATH=/usr/local/mysql/bin:$PATH' >> /etc/profile

[root@centos6 ~]# tail -1 /etc/profile

export PATH=/usr/local/mysql/bin:$PATH

[root@centos6 ~]# source /etc/profile

 [root@centos6~]# echo $PATH

/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

 

8、初始化MYSQL多实例数据库文件

[root@centos6 scripts]# pwd

/usr/local/mysql/scripts

[root@centos6 scripts]# ./mysql_install_db--basedir=/usr/local/mysql --datadir=/home/mysql/data3306 --user=mysql

[root@centos6 scripts]# ./mysql_install_db--basedir=/usr/local/mysql --datadir=/home/mysql/data3307 --user=mysql

 

9、启动MYSQL多实例数据库

[root@centos6 ~]# mysqld_safe--defaults-file=/home/mysql/data3306/my.cnf 2>&1 > /dev/null &

[root@centos6 ~]# mysqld_safe --defaults-file=/home/mysql/data3307/my.cnf2>&1 > /dev/null &

 

10、设置密码登录

[root@centos6 ~]# mysqladmin -S/home/mysql/data3306/mysqld.sock -uroot password '123456'

[root@centos6 ~]# mysqladmin -S/home/mysql/data3307/mysqld.sock -uroot password '123456'

 

11、登录实例,并删除test库及空密码账户

[root@centos6 ~]# mysql  -S /home/mysql/data3306/mysqld.sock -uroot -p

Enter password:

mysql> status;

mysql> show databases;

mysql> drop database test;

mysql> use mysql;

mysql> select user,host,password fromuser;

mysql> delete from  user where password='';

mysql> flush privileges;

 

12、停库

[root@centos6 ~]# mysqladmin shutdown -S/home/mysql/data3306/mysqld.sock -u root -p

Enter password:

[root@centos6 ~]# mysqladmin shutdown -S/home/mysql/data3307/mysqld.sock -u root -p

Enter password:

[root@centos6 ~]# ps -ef|grep mysqld|grep-v grep

[root@centos6 ~]# netstat -tunlp|grep 330

 


你可能感兴趣的:(多独立配置文件,多实例MYSQL5.6)