mysql数据库多实例部署

本文系统:rhel5.8

ip : 192.168.100.150

数据库版本:mysql-5.6.15

1、创建部署mysql服务账号:

[root@daf ~]# useradd -d /opt/mysql mysql
[root@daf ~]# echo "mysql" |passwd --stdin mysql
Changing password for user mysql.
passwd: all authentication tokens updated successfully.

2、解压无需免装包:配置环境变量

[mysql@daf ~]$ tar zxvf mysql-5.6.15-linux-glibc2.5-x86_64.tar.gz
[mysql@daf ~]$ mv mysql-5.6.15-linux-glibc2.5-x86_64 mysql-5.6.15

[mysql@daf mysql-5.6.15]$ vim ~/.bash_profile

MYSQL_HOME=/opt/mysql/mysql-5.6.15
export MYSQL_HOME

PATH=$MYSQL_HOME/bin:$PATH
export PATH

3、配置多实例数据库配置文件

[root@daf ~]# mkdir /Data_for_Mysql
[root@daf ~]# chown mysql.mysql -R /Data_for_Mysql/
[root@daf ~]# su - mysql
[mysql@daf ~]$ mkdir -p /Data_for_Mysql/3301/data /Data_for_Mysql/3301/logs
[mysql@daf ~]$ touch /Data_for_Mysql/3301/my.cnf
[mysql@daf ~]$ mkdir -p /Data_for_Mysql/3302/data /Data_for_Mysql/3302/logs
[mysql@daf ~]$ touch /Data_for_Mysql/3302/my.cnf

目录结构:

[mysql@daf Data_for_Mysql]$ pwd
/Data_for_Mysql
[mysql@daf Data_for_Mysql]$ tree
.
|-- 3301
|   |-- data
|   |-- logs
|   `-- my.cnf
`-- 3302
    |-- data
    |-- logs
    `-- my.cnf

6 directories, 2 files
[mysql@daf Data_for_Mysql]$

配置my.cnf ######本配置文件只供参考

[mysql@daf 3301]$ vim /Data_for_Mysql/3301/my.cnf
[client]
port = 3301
socket = /Data_for_Mysql/3301/data/mysql.sock
[mysqld]
user=msql
port=3301
bind-address=192.168.100.150
socket = /Data_for_Mysql/3301/data/mysql.sock.3301
pid-file = /Data_for_Mysql/3301/data/mysql.pid
basedir = /opt/mysql/mysql-5.6.15
datadir = /Data_for_Mysql/3301/data
server-id=1
log-bin=mysql-bin
log-bin-index= mysql-bin.index

# LOGGING
log_error=/Data_for_Mysql/3301/logs/mysql-error.log
slow_query_log_file= /Data_for_Mysql/3301/logs/mysql-slow.log
slow_query_log=1

character-sets-dir = /opt/mysql/mysql-5.6.15/share/charsets
back_log = 2000
max_connections = 1000
connect-timeout = 60
wait-timeout = 28800
net_buffer_length = 16384
max_allowed_packet = 64M
thread_stack = 192K
thread_cache_size = 20
thread_concurrency = 128
query_cache_size = 256M
query_cache_limit = 2M
query_cache_min_res_unit = 2

default-time-zone = system
character-set-server = utf8
default-storage-engine = InnoDB

tmp_table_size = 512M
max_heap_table_size = 512M

max_binlog_size = 1G
max_relay_log_size = 1G

[mysql]
disable-auto-rehash
default-character-set = utf8

4、初始化数据库

[mysql@daf scripts]$ pwd
/opt/mysql/mysql-5.6.15/scripts
[mysql@daf scripts]$ ./mysql_install_db --defaults-file=/Data_for_Mysql/3301/my.cnf --user=mysql --basedir=/opt/mysql/mysql-5.6.15 --datadir=/Data_for_Mysql/3301/data/

5、启动3301实例数据库  ###启动数据库必须在mysql目录;

[mysql@daf mysql-5.6.15]$ pwd
/opt/mysql/mysql-5.6.15
[mysql@daf mysql-5.6.15]$ mysqld_safe --defaults-file=/Data_for_Mysql/3301/my.cnf --user=mysql --basedir=/opt/mysql/mysql-5.6.15 --datadir=/Data_for_Mysql/3301/data/ &

[mysql@daf mysql-5.6.15]$ netstat -nat |grep 3301
tcp        0      0 192.168.100.150:3301        0.0.0.0:*                   LISTEN

Ps:3302 实例操作和上面一样,只需改动端口及相应目录即可;

3302配置文件:

[mysql@daf 3302]$ cat my.cnf
[client]
port = 3302
socket = /Data_for_Mysql/3302/data/mysql.sock
[mysqld]
user=mysql
port=3302
bind-address=192.168.100.150
socket = /Data_for_Mysql/3302/data/mysql.sock.3302
pid-file = /Data_for_Mysql/3302/data/mysql.pid
basedir = /opt/mysql/mysql-5.6.15
datadir = /Data_for_Mysql/3302/data
server-id=1
log-bin=mysql-bin
log-bin-index= mysql-bin.index

# LOGGING
log_error=/Data_for_Mysql/3302/logs/mysql-error.log
slow_query_log_file= /Data_for_Mysql/3302/logs/mysql-slow.log
slow_query_log=1

character-sets-dir = /opt/mysql/mysql-5.6.15/share/charsets
back_log = 2000
max_connections = 1000
connect-timeout = 60
wait-timeout = 28800
net_buffer_length = 16384
max_allowed_packet = 64M
thread_stack = 192K
thread_cache_size = 20
thread_concurrency = 128
query_cache_size = 256M
query_cache_limit = 2M
query_cache_min_res_unit = 2

default-time-zone = system
character-set-server = utf8
default-storage-engine = InnoDB

tmp_table_size = 512M
max_heap_table_size = 512M

max_binlog_size = 1G
max_relay_log_size = 1G

[mysql]
disable-auto-rehash
default-character-set = utf8

3302 实例初始化;

[mysql@daf scripts]$ pwd
/opt/mysql/mysql-5.6.15/scripts
[mysql@daf scripts]$ ./mysql_install_db --defaults-file=/Data_for_Mysql/3302/my.cnf --user=mysql --basedir=/opt/mysql/mysql-5.6.15 --datadir=/Data_for_Mysql/3302/data/

3302 启动该实例:

[mysql@daf mysql-5.6.15]$ mysqld_safe --defaults-file=/Data_for_Mysql/3302/my.cnf --user=mysql --basedir=/opt/mysql/mysql-5.6.15 --datadir=/Data_for_Mysql/3302/data/ &

[mysql@daf mysql-5.6.15]$ netstat -nat |grep 330
tcp        0      0 192.168.100.150:3301        0.0.0.0:*                   LISTEN
tcp        0      0 192.168.100.150:3302        0.0.0.0:*                   LISTEN

6、创建root密码,要区别实例

[mysql@daf mysql-5.6.15]$ mysqladmin -uroot password 'root123' -S /Data_for_Mysql/3301/data/mysql.sock.3301

6.1、关闭mysql,区别实例

[mysql@daf mysql-5.6.15]$ mysqladmin -uroot -proot123 -S /Data_for_Mysql/3301/data/mysql.sock.3301 shutdown
Warning: Using a password on the command line interface can be insecure.
150402 15:44:52 mysqld_safe mysqld from pid file /Data_for_Mysql/3301/data/mysql.pid ended
[1]-  Done                    mysqld_safe --defaults-file=/Data_for_Mysql/3301/my.cnf --user=mysql --basedir=/opt/mysql/mysql-5.6.15 --datadir=/Data_for_Mysql/3301/data/


你可能感兴趣的:(数据库,mysql,mysql5.6,多实例)