mysql5.5.32多实例配置方案

本文涉及的产品
云数据库 RDS MySQL,集群版 2核4GB 100GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,高可用版 2核4GB 50GB
简介:

操作系统:CentOS release 6.7 (Final)

内核版本:2.6.32-573.el6.x86_64

mysql版本号:mysql-5.5.32


1)安装mysql所需的依赖包

1
2
3
4
5
6
7
8
9
10
# adduser mysql -s /sbin/nologin -M
# mkdir -p /data/{3306,3307}/data
# tree /data/
/data/
├── 3306
│?? └── data
└── 3307
     └── data
4 directories, 0 files
# yum -y install ncurse-devel libaio-devel

2)安装编译mysql需要的软件

1
2
3
4
5
6
# tar xf cmake-2.8.8.tar.gz 
# cd cmake-2.8.8
# ./configure
# gmake
# which cmake
/usr/bin/cmake

3)采用编译安装mysql

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# ls -l |grep mysql
-rw-r--r--  1 root    root 186722932 6月  27 05:03 mysql-5.5.32-linux2.6-x86_64. tar .gz
-rw-r--r--  1 root    root  24596474 6月  27 05:10 mysql-5.5.32. tar .gz
说明:mysql-5.5.32-linux2.6-x86_64. tar .gz为二进制安装包、mysql-5.5.32. tar .gz为源码安装包
# tar xf mysql-5.5.32.tar.gz 
# cd mysql-5.5.32
# cmake . -DCMAKE_INSTALL_PREFIX=/application/mysql-5.5.32 \
-DMYSQL_DATADIR= /application/mysql-5 .5.32 /data  \
-DMYSQL_UNIX_ADDR= /application/mysql-5 .5.32 /tmp/mysql .sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii \
-DENABLED_LOCAL_INFILE=ON \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITHOUT_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FAST_MUTEXES=1 \
-DWITH_ZLIB=bundled \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_READLINE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DWITH_DEBUG=0
# make
# make install

4)创建mysql多实例的数据文件目录

1
2
3
4
5
6
7
8
9
10
11
# mkdir -p /data/{3306,3307}/data
# tree /data
# ln -s /application/mysql-5.5.32/ /application/mysql
# ll /application/mysql
lrwxrwxrwx 1 root root 26 10月  8 22:50  /application/mysql  ->  /application/mysql-5 .5.32/
# cd /data/3306
# ls -lrt
总用量 12
drwxr-xr-x 2 root root 4096 10月  8 21:13 data
-rw-r--r-- 1 root root 1899 10月 29 2013 my.cnf
-rw-r--r-- 1 root root 1307 7月  15 2013 mysql

5)编辑mysql实例配置文件


a、创建3306实例配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# vim /data/3306/my.cnf 
[client]
port            = 3306
socket          =  /data/3306/mysql .sock
[mysql]
no-auto-rehash
[mysqld]
user    = mysql
port    = 3306
socket  =  /data/3306/mysql .sock
basedir =  /application/mysql
datadir =  /data/3306/data
open_files_limit    = 1024
back_log = 600
max_connections = 800
max_connect_errors = 3000
table_cache = 614
external-locking = FALSE
max_allowed_packet =8M
sort_buffer_size = 1M
join_buffer_size = 1M
thread_cache_size = 100
thread_concurrency = 2
query_cache_size = 2M
query_cache_limit = 1M
query_cache_min_res_unit = 2k
#default_table_type = InnoDB
thread_stack = 192K
#transaction_isolation = READ-COMMITTED
tmp_table_size = 2M
max_heap_table_size = 2M
long_query_time = 1
#log_long_format
#log-error = /data/3306/error.log
#log-slow-queries = /data/3306/slow.log
pid- file  /data/3306/mysql .pid
log-bin =  /data/3306/mysql-bin
relay-log =  /data/3306/relay-bin
relay-log-info- file  /data/3306/relay-log .info
binlog_cache_size = 1M
max_binlog_cache_size = 1M
max_binlog_size = 2M
expire_logs_days = 7
key_buffer_size = 16M
read_buffer_size = 1M
read_rnd_buffer_size = 1M
bulk_insert_buffer_size = 1M
#myisam_sort_buffer_size = 1M
#myisam_max_sort_file_size = 10G
#myisam_max_extra_sort_file_size = 10G
#myisam_repair_threads = 1
#myisam_recover
lower_case_table_names = 1
skip-name-resolve
slave-skip-errors = 1032,1062
replicate-ignore-db=mysql
server- id  = 1
innodb_additional_mem_pool_size = 4M
innodb_buffer_pool_size = 32M
innodb_data_file_path = ibdata1:128M:autoextend
innodb_file_io_threads = 4
innodb_thread_concurrency = 8
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 2M
innodb_log_file_size = 4M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
innodb_file_per_table = 0
[mysqldump]
quick
max_allowed_packet = 2M
[mysqld_safe]
log-error= /data/3306/mysql_oldboy3306 .err
pid- file = /data/3306/mysqld .pid

b、创建3306实例启动脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# vim /data/3306/mysql 
#!/bin/sh
#init
port=3306
mysql_user= "root"
mysql_pwd= "redhat12345"
CmdPath= "/application/mysql/bin"
mysql_sock= "/data/${port}/mysql.sock"
#startup function
function_start_mysql()
{
     if  [ ! -e  "$mysql_sock"  ]; then
       printf  "Starting MySQL...\n"
       /bin/sh  ${CmdPath} /mysqld_safe  --defaults- file = /data/ ${port} /my .cnf 2>&1 >  /dev/null  &
     else
       printf  "MySQL is running...\n"
       exit
     fi
}
#stop function
function_stop_mysql()
{
     if  [ ! -e  "$mysql_sock"  ]; then
        printf  "MySQL is stopped...\n"
        exit
     else
        printf  "Stoping MySQL...\n"
${CmdPath} /mysqladmin  -u ${mysql_user} -p${mysql_pwd} -S  /data/ ${port} /mysql .sock 
shutdown
    fi
}
#restart function
function_restart_mysql()
{
     printf  "Restarting MySQL...\n"
     function_stop_mysql
     sleep  2
     function_start_mysql
}
case  $1  in
start)
     function_start_mysql
;;
stop)
     function_stop_mysql
;;
restart)
     function_restart_mysql
;;
*)
     printf  "Usage: /data/${port}/mysql {start|stop|restart}\n"
esac


c、创建3307实例配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# vim /data/3307/my.cnf 
[client]
port            = 3307
socket          =  /data/3307/mysql .sock
[mysql]
no-auto-rehash
[mysqld]
user    = mysql
port    = 3307
socket  =  /data/3307/mysql .sock
basedir =  /application/mysql
datadir =  /data/3307/data
open_files_limit    = 1024
back_log = 600
max_connections = 800
max_connect_errors = 3000
table_cache = 614
external-locking = FALSE
max_allowed_packet =8M
sort_buffer_size = 1M
join_buffer_size = 1M
thread_cache_size = 100
thread_concurrency = 2
query_cache_size = 2M
query_cache_limit = 1M
query_cache_min_res_unit = 2k
#default_table_type = InnoDB
thread_stack = 192K
#transaction_isolation = READ-COMMITTED
tmp_table_size = 2M
max_heap_table_size = 2M
#long_query_time = 1
#log_long_format
#log-error = /data/3307/error.log
#log-slow-queries = /data/3307/slow.log
pid- file  /data/3307/mysql .pid
#log-bin = /data/3307/mysql-bin
relay-log =  /data/3307/relay-bin
relay-log-info- file  /data/3307/relay-log .info
binlog_cache_size = 1M
max_binlog_cache_size = 1M
max_binlog_size = 2M
expire_logs_days = 7
key_buffer_size = 16M
read_buffer_size = 1M
read_rnd_buffer_size = 1M
bulk_insert_buffer_size = 1M
#myisam_sort_buffer_size = 1M
#myisam_max_sort_file_size = 10G
#myisam_max_extra_sort_file_size = 10G
#myisam_repair_threads = 1
#myisam_recover
lower_case_table_names = 1
skip-name-resolve
slave-skip-errors = 1032,1062
replicate-ignore-db=mysql
server- id  = 3
innodb_additional_mem_pool_size = 4M
innodb_buffer_pool_size = 32M
innodb_data_file_path = ibdata1:128M:autoextend
innodb_file_io_threads = 4
innodb_thread_concurrency = 8
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 2M
innodb_log_file_size = 4M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
innodb_file_per_table = 0
[mysqldump]
quick
max_allowed_packet = 2M
[mysqld_safe]
log-error= /data/3307/mysql_oldboy3307 .err
pid- file = /data/3307/mysqld .pid


d、创建3307实例启动脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/sh
#init
port=3307
mysql_user= "root"
mysql_pwd= "redhat12345"
CmdPath= "/application/mysql/bin"
mysql_sock= "/data/${port}/mysql.sock"
#startup function
function_start_mysql()
{
     if  [ ! -e  "$mysql_sock"  ]; then
       printf  "Starting MySQL...\n"
       /bin/sh  ${CmdPath} /mysqld_safe  --defaults- file = /data/ ${port} /my .cnf 2>&1 >  /dev/null  &
     else
       printf  "MySQL is running...\n"
       exit
     fi
}
#stop function
function_stop_mysql()
{
     if  [ ! -e  "$mysql_sock"  ]; then
        printf  "MySQL is stopped...\n"
        exit
     else
        printf  "Stoping MySQL...\n"
        ${CmdPath} /mysqladmin  -u ${mysql_user} -p${mysql_pwd} -S  /data/ ${port} /mysql .sock  shutdown
    fi
}
#restart function
function_restart_mysql()
{
     printf  "Restarting MySQL...\n"
     function_stop_mysql
     sleep  2
     function_start_mysql
}
case  $1  in
start)
     function_start_mysql
;;
stop)
     function_stop_mysql
;;
restart)
     function_restart_mysql
;;
*)
     printf  "Usage: /data/${port}/mysql {start|stop|restart}\n"
esac

6)配置mysql多实例的文件权限

1
2
3
4
5
6
7
8
# chown -R mysql.mysql /data
# find /data -name mysql|xargs ls -l
-rw-r--r-- 1 mysql mysql 1312 10月  8 23:03  /data/3306/mysql
-rw-r--r-- 1 mysql mysql 1312 10月  8 23:03  /data/3307/mysql
# find /data -name mysql|xargs chmod 700
# find /data -name mysql|xargs ls -l
-rwx------ 1 mysql mysql 1312 10月  8 23:03  /data/3306/mysql
-rwx------ 1 mysql mysql 1312 10月  8 23:03  /data/3307/mysql

7)将mysql相关命令加入全局路径

1
2
3
4
5
6
7
8
# ls /application/mysql/bin/mysql
/application/mysql/bin/mysql
# echo 'export PATH=/application/mysql/bin:$PATH'>>/etc/profile
# tail -1 /etc/profile
export  PATH= /application/mysql/bin :$PATH
# source /etc/profile
# echo $PATH
/application/mysql/bin : /application/mysql/bin/ : /application/nginx/sbin/ : /application/mysql/bin/ : /application/nginx/sbin/ : /usr/lib64/qt-3 .3 /bin : /usr/kerberos/sbin : /usr/kerberos/bin : /usr/local/sbin : /usr/local/bin : /sbin : /bin : /usr/sbin : /usr/bin : /root/bin

8)初始化实例的数据库文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# ./mysql_install_db --basedir=/application/mysql --datadir=/data/3306/data --user=mysql
# ./mysql_install_db --basedir=/application/mysql --datadir=/data/3307/data --user=mysql
# echo $?
0
# 启动多实例
# /data/3306/mysql start
Starting MySQL...
# /data/3307/mysql start
Starting MySQL...
# 查看数据库
# netstat -tunlp | grep 330*
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      28533 /mysqld        
tcp        0      0 0.0.0.0:3307                0.0.0.0:*                   LISTEN      29250 /mysqld 
# 配置mysql多实例数据库开机自启动
# echo "# mysql multi instances startup">>/etc/rc.local
#  echo  "rm -rf /data/3306/mysql.sock">>/etc/rc.local
#  echo  "rm -rf /data/3307/mysql.sock">>/etc/rc.local
# echo "/data/3306/mysql start">>/etc/rc.local 
# echo "/data/3307/mysql start">>/etc/rc.local 
# 登录mysql进行测试:
# mysql -S /data/3306/mysql.sock 
# mysql -S /data/3307/mysql.sock

9) mysql安全设置

1
2
# mysqladmin -u root -S /data/3306/mysql.sock password 'redhat12345'
# mysqladmin -u root -S /data/3307/mysql.sock password 'redhat12345'

10) 登录进入mysql

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# mysql -uroot -S /data/3306/mysql.sock -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection  id  is 4
Server version: 5.5.32-log Source distribution
Copyright (c) 2000, 2013, Oracle and /or  its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and /or  its
affiliates. Other names may be trademarks of their respective
owners.
Type  'help;'  or  '\h'  for  help. Type  '\c'  to  clear  the current input statement.
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
test                |
+--------------------+
4 rows  in  set  (0.00 sec)
mysql>  select  user();
+----------------+
| user()         |
+----------------+
| root@localhost |
+----------------+
1 row  in  set  (0.00 sec)
# find /data -type f -name "mysql" -exec chown root.root {} \;
# find /data -type f -name "mysql" -exec chmod 700 {} \;
# find /data -type f -name "mysql" -exec ls -l {} \;
-rwx------ 1 root root 1312 10月  8 23:03  /data/3306/mysql
-rwx------ 1 root root 1312 10月  8 23:03  /data/3307/mysql

11) mysql的启停测试

1
2
3
4
5
6
7
8
9
# /data/3306/mysql stop
Stoping MySQL...
# netstat -tunlp | grep 330*
tcp        0      0 0.0.0.0:3307                0.0.0.0:*                   LISTEN      29250 /mysqld        
# /data/3306/mysql start
Starting MySQL...      
# netstat -tunlp | grep 330*
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      30168 /mysqld        
tcp        0      0 0.0.0.0:3307                0.0.0.0:*                   LISTEN      29250 /mysqld

12) 在远程主机进行测试


a、服务器端创建数据库并添加授权账号

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
mysql> create database wanlong;
Query OK, 1 row affected (0.00 sec)
mysql> create user wan identified by  "redhat" ;
Query OK, 0 rows affected (0.00 sec)
mysql> grant all privileges on wanlong.* to  'wan' @ '10.10.10.%'  identified by  'redhat'  with grant option;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
test                |
| wanlong            |
+--------------------+
5 rows  in  set  (0.00 sec)

b、客户端进行访问:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# mysql -uwan -predhat -h 10.10.10.129
-u:用户名
-p:密码
-h:远程主机
mysql>   select  user();
+------------------+
| user()           |
+------------------+
| wan@10.10.10.130 |
+------------------+
1 row  in  set  (0.00 sec)
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
test                |
| wanlong            |
+--------------------+
3 rows  in  set  (0.01 sec)










本文转自 冰冻vs西瓜 51CTO博客,原文链接:http://blog.51cto.com/molewan/1860198,如需转载请自行联系原作者
相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
1天前
|
关系型数据库 MySQL 数据库
|
8天前
|
分布式计算 大数据 关系型数据库
MaxCompute产品使用合集之如何实现类似mysql实例中的数据库功能
MaxCompute作为一款全面的大数据处理平台,广泛应用于各类大数据分析、数据挖掘、BI及机器学习场景。掌握其核心功能、熟练操作流程、遵循最佳实践,可以帮助用户高效、安全地管理和利用海量数据。以下是一个关于MaxCompute产品使用的合集,涵盖了其核心功能、应用场景、操作流程以及最佳实践等内容。
|
14天前
|
运维 关系型数据库 MySQL
【实操记录】MySQL主从配置
本文使用MySQL原生支持的主从同步机制,详细记录了配置步骤及运维操作方法,可供大家直接参考、使用。 本文假设已经部署了两台主机的MySQL软件,且数据库服务正常,详细部署步骤可本站搜索:"mysql二进制安装包部署"
35 0
|
23天前
|
SQL 关系型数据库 MySQL
【MySQL】主从异步复制配置
【MySQL】主从异步复制配置
20 1
|
7天前
|
分布式计算 DataWorks 关系型数据库
MaxCompute操作报错合集之配置mysql数据源querysql模式,同步到MC时遇到报错,该怎么处理
MaxCompute是阿里云提供的大规模离线数据处理服务,用于大数据分析、挖掘和报表生成等场景。在使用MaxCompute进行数据处理时,可能会遇到各种操作报错。以下是一些常见的MaxCompute操作报错及其可能的原因与解决措施的合集。
|
9天前
|
SQL DataWorks 关系型数据库
DataWorks产品使用合集之如何配置MySQL数据源
DataWorks作为一站式的数据开发与治理平台,提供了从数据采集、清洗、开发、调度、服务化、质量监控到安全管理的全套解决方案,帮助企业构建高效、规范、安全的大数据处理体系。以下是对DataWorks产品使用合集的概述,涵盖数据处理的各个环节。
|
10天前
|
存储 SQL 关系型数据库
实时计算 Flink版产品使用问题之要配置MySQL集群存储节点,该如何配置
实时计算Flink版作为一种强大的流处理和批处理统一的计算框架,广泛应用于各种需要实时数据处理和分析的场景。实时计算Flink版通常结合SQL接口、DataStream API、以及与上下游数据源和存储系统的丰富连接器,提供了一套全面的解决方案,以应对各种实时计算需求。其低延迟、高吞吐、容错性强的特点,使其成为众多企业和组织实时数据处理首选的技术平台。以下是实时计算Flink版的一些典型使用合集。
|
14天前
|
网络协议 关系型数据库 MySQL
MySQL PXC集群配置IPv6
前阵子为PXC集群配置IPv6支持,遇见奇怪的问题,就是SST同步时总是报错,为此在官网论坛提交了问题,未得到答案,最后偶然得到了答案
23 0
|
20天前
|
存储 关系型数据库 MySQL
探索MySQL:关系型数据库的基石
MySQL,作为全球最流行的开源关系型数据库管理系统(RDBMS)之一,广泛应用于各种Web应用、企业级应用和数据仓库中
|
18天前
|
缓存 运维 关系型数据库
数据库容灾 | MySQL MGR与阿里云PolarDB-X Paxos的深度对比
经过深入的技术剖析与性能对比,PolarDB-X DN凭借其自研的X-Paxos协议和一系列优化设计,在性能、正确性、可用性及资源开销等方面展现出对MySQL MGR的多项优势,但MGR在MySQL生态体系内也占据重要地位,但需要考虑备库宕机抖动、跨机房容灾性能波动、稳定性等各种情况,因此如果想用好MGR,必须配备专业的技术和运维团队的支持。 在面对大规模、高并发、高可用性需求时,PolarDB-X存储引擎以其独特的技术优势和优异的性能表现,相比于MGR在开箱即用的场景下,PolarDB-X基于DN的集中式(标准版)在功能和性能都做到了很好的平衡,成为了极具竞争力的数据库解决方案。