mysql-5.5.37多实例的安装

CentOS 6.2下安装编译mysql-5.5.37  ##多实例 原理也是先安装单实例后面安装多实例

首先yum安装

yum install gcc gcc-c++ cmake ncurses-devel bison

1 单实例Mysql数据库的安装

1.1 建立mysql账号

[[email protected] ~]# groupadd mysql

[[email protected] ~]# useradd -s /sbin/nologin -g mysql -M mysql   ##-M表示不创建家目录

创建完成之后查看下

[[email protected] ~]# grep mysql /etc/passwd

mysql:x:500:500::/home/mysql:/sbin/nologin

1.2建立mysql的安装目录

[[email protected] ~]# mkdir -p /usr/local/mysql

[[email protected] ~]# mkdir -p /data/mysql/data

1.3下载mysql http://dev.mysql.com/downloads/ 或者去搜狐镜像源下载 然后上传到服务器

2;安装mysql

2,1检测系统原来是否有安装过mysql

[[email protected] ~]# rpm -qa |grep mysql

mysql-libs-5.1.61-1.el6_2.1.i686

这里是没有安装过mysql 如果有的话就需要先卸载mysql安装包 rpm -e --nodeps mysql.X.X.X

2,2安装编译mysql编译所需要的包

yum -y install make gcc-c++ cmake bison-devel  ncurses-devel

如果前面安装过这些包的话可以分开查询下再安装

2,3解压mysql并安装

[[email protected] ~]# tar xzvf mysql-5.5.37.tar.gz

[[email protected] ~]# cd mysql-5.5.37

cmake \

-DMYSQL_USER=mysql \

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \

-DINSTALL_DATADIR=/data/mysql/data \

-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci \

-DEXTRA_CHARSETS=all \

-DWITH_EMBEDDED_SERVER=1 \

-DENABLED_LOCAL_INFILE=1 \

-DWITH_MYISAM_STORAGE_ENGINE=1 \

-DWITH_INNOBASE_STORAGE_ENGINE=1

-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \       #套接字文件

[[email protected] mysql-5.6.23]# make && make install

3;初始化数据库

[[email protected] mysql]# mkdir -p /data/mysql/data/{3306,3307}  ##建立两个实例

/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mysql/data/3306 --user=mysql

/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mysql/data/3307 --user=mysql

chown -R mysql:mysql /usr/local/mysql

chown -R mysql:mysql /data/mysql/data

4;创建配置文件

3306 my.cnf

[client]

port = 3306

socket = /data/mysql/data/3306/mysql.sock

[mysqld]

datadir=/data/mysql/data/3306

skip-name-resolve

lower_case_table_names=1

innodb_file_per_table=1

port = 3306

socket =/data/mysql/data/3306/mysql.sock

back_log = 50

max_connections = 300

max_connect_errors = 1000

table_open_cache = 2048

max_allowed_packet = 16M

binlog_cache_size = 2M

max_heap_table_size = 64M

sort_buffer_size = 2M

join_buffer_size = 2M

thread_cache_size = 64

thread_concurrency = 8

query_cache_size = 64M

query_cache_limit = 2M

ft_min_word_len = 4

default-storage-engine = innodb

thread_stack = 192K

transaction_isolation = REPEATABLE-READ

tmp_table_size = 64M

log-bin=mysql-bin

binlog_format=mixed

slow_query_log

long_query_time = 1

server-id = 1

key_buffer_size = 8M

read_buffer_size = 2M

read_rnd_buffer_size = 2M

bulk_insert_buffer_size = 64M

myisam_sort_buffer_size = 128M

myisam_max_sort_file_size = 10G

myisam_repair_threads = 1

myisam_recover

innodb_additional_mem_pool_size = 16M

innodb_buffer_pool_size = 200M

innodb_data_file_path = ibdata1:10M:autoextend

innodb_file_io_threads = 8

innodb_thread_concurrency = 16

innodb_flush_log_at_trx_commit = 1

innodb_log_buffer_size = 16M

innodb_log_file_size = 512M

innodb_log_files_in_group = 3

innodb_max_dirty_pages_pct = 60

innodb_lock_wait_timeout = 120

[mysqldump]

quick

max_allowed_packet = 256M

[mysql]

no-auto-rehash

prompt=\\[email protected]\\d \\R:\\m>

[myisamchk]

key_buffer_size = 512M

sort_buffer_size = 512M

read_buffer = 8M

write_buffer = 8M

[mysqlhotcopy]

interactive-timeout

[mysqld_safe]

open-files-limit = 8192

3307 my.cnf

[client]

port = 3307

socket = /data/mysql/data/3307/mysql.sock

[mysqld]

datadir=/data/mysql/data/3307

skip-name-resolve

lower_case_table_names=1

innodb_file_per_table=1

port = 3307

socket =/data/mysql/data/3307/mysql.sock

back_log = 50

max_connections = 300

max_connect_errors = 1000

table_open_cache = 2048

max_allowed_packet = 16M

binlog_cache_size = 2M

max_heap_table_size = 64M

sort_buffer_size = 2M

join_buffer_size = 2M

thread_cache_size = 64

thread_concurrency = 8

query_cache_size = 64M

query_cache_limit = 2M

ft_min_word_len = 4

default-storage-engine = innodb

thread_stack = 192K

transaction_isolation = REPEATABLE-READ

tmp_table_size = 64M

log-bin=mysql-bin

binlog_format=mixed

slow_query_log

long_query_time = 1

server-id = 1

key_buffer_size = 8M

read_buffer_size = 2M

read_rnd_buffer_size = 2M

bulk_insert_buffer_size = 64M

myisam_sort_buffer_size = 128M

myisam_max_sort_file_size = 10G

myisam_repair_threads = 1

myisam_recover

innodb_additional_mem_pool_size = 16M

innodb_buffer_pool_size = 200M

innodb_data_file_path = ibdata1:10M:autoextend

innodb_file_io_threads = 8

innodb_thread_concurrency = 16

innodb_flush_log_at_trx_commit = 1

innodb_log_buffer_size = 16M

innodb_log_file_size = 512M

innodb_log_files_in_group = 3

innodb_max_dirty_pages_pct = 60

innodb_lock_wait_timeout = 120

[mysqldump]

quick

max_allowed_packet = 256M

[mysql]

no-auto-rehash

prompt=\\[email protected]\\d \\R:\\m>

[myisamchk]

key_buffer_size = 512M

sort_buffer_size = 512M

read_buffer = 8M

write_buffer = 8M

[mysqlhotcopy]

interactive-timeout

[mysqld_safe]

open-files-limit = 8192

5;定义全局

[[email protected] mysql-5.5.37]# echo "export PATH=/usr/local/mysql/bin/:$PATH" >>/etc/profile

[[email protected] mysql-5.5.37]#source /etc/profile

6;启动mysql

多实例地区文件的启动mysql服务实质:

mysqld_safe --defaults-file=/data/mysql/data/3306/my.cnf 2>&1 > /dev/null &

mysqld_safe --defaults-file=/data/mysql/data/3307/my.cnf 2>&1 > /dev/null &

6;登陆

[[email protected] 3307]# /usr/local/mysql/bin/mysql -uroot -p -S /data/mysql/data/3306/mysql.sock

[[email protected] 3307]# /usr/local/mysql/bin/mysql -uroot -p -S /data/mysql/data/3307/mysql.sock

7;停止mysql

/usr/local/mysql/bin/mysqladmin -u root -p  -S /data/mysql/data/3306/mysql.sock shutdown

/usr/local/mysql/bin/mysqladmin -u root -p  -S /data/mysql/data/3307/mysql.sock shutdown

8;启动脚本编写

[[email protected] 3306]# vi mysqld

[[email protected] 3306]# chmod 700 mysqld

#!/bin/bash

mysql_port=3306

mysql_username="root"

#if passwd the set password

mysql_password="123"

function_start_mysql()

{

printf "Starting MySQL...\n"

}

function_stop_mysql()

{

printf "Stoping MySQL...\n"

/usr/local/mysql/bin/mysqladmin -u ${mysql_username} -p${mysql_password} -S /data/mysql/data/${mysql_port}/mysql.sock shutdown

}

function_restart_mysql()

{

printf "Restarting MySQL...\n"

function_stop_mysql

function_start_mysql

}

function_kill_mysql()

{

kill -9 $(ps -ef | grep ‘bin/mysqld_safe‘ | grep ${mysql_port} | awk ‘{printf $2}‘)

kill -9 $(ps -ef | grep ‘libexec/mysqld‘ | grep ${mysql_port} | awk ‘{printf $2}‘)

}

case $1 in

start)

function_start_mysql;;

stop)

function_stop_mysql;;

kill)

function_kill_mysql;;

restart)

function_stop_mysql

function_start_mysql;;

*)

echo "Usage: /data/mysql/data/${mysql_port}/mysqld {start|stop|restart|kill}";;

esac

#编写3307脚本

#!/bin/bash

mysql_port=3307

mysql_username="root"

mysql_password="123"

function_start_mysql()

{

printf "Starting MySQL...\n"

}

function_stop_mysql()

{

printf "Stoping MySQL...\n"

}

function_restart_mysql()

{

printf "Restarting MySQL...\n"

function_stop_mysql

function_start_mysql

}

function_kill_mysql()

{

kill -9 $(ps -ef | grep ‘bin/mysqld_safe‘ | grep ${mysql_port} | awk ‘{printf $2}‘)

kill -9 $(ps -ef | grep ‘libexec/mysqld‘ | grep ${mysql_port} | awk ‘{printf $2}‘)

}

case $1 in

start)

function_start_mysql;;

stop)

function_stop_mysql;;

kill)

function_kill_mysql;;

restart)

function_stop_mysql

function_start_mysql;;

*)

echo "Usage: /data/mysql/data/${mysql_port}/mysqld {start|stop|restart|kill}";;

esac

启动方式:

/data/mysql/data/3306/mysqld start

/data/mysql/data/3307/mysqld start

[[email protected] 3307]# /data/mysql/data/3306/mysqld restart

Stoping MySQL...

Starting MySQL...

[[email protected] 3307]# /data/mysql/data/3307/mysqld restart

Stoping MySQL...

Starting MySQL...

9;开机自启动mysql

[[email protected] 3307]# vi /etc/rc.local

/data/mysql/data/3306/mysqld start >/dev/null 2>&1

/data/mysql/data/3307/mysqld start >/dev/null 2>&1

时间: 2024-12-28 23:41:05

mysql-5.5.37多实例的安装的相关文章

MySQL 5.6.37源码编译安装

MySQL 5.6.37 编译安装 什么是数据库? 简单的说,数据库(database)就是一个存放数据的仓库,这个仓库是按照一定的数据结构(数据结构是指数据的组织形式或数据之间的联系)来组织.存储的,我们可以通过数据提供的多种方法来管理数据库里的数据. 数据库的种类 按照早起的数据库理论,比较流行的数据库模型有三种,分别为层次式数据库.网络式数据库和关系型数据库,而在当今的互联网中,最常用的数据库模型主要是两种,即关系型数据库和非关系型数据库. 什么是关系型数据库? 关系型数据库模型是把复杂的

3.4 实例 playbook安装mysql

1.创建mysql的playbook结构 1234567891011 [[email protected] roles]# pwd/etc/ansible/roles[[email protected] roles]# mkdir -p mysql_install/{files,handlers,meta,tasks,templates,vars}[[email protected] roles]# tree mysql_install/mysql_install/├── files├── ha

源码安装mysql5.6.20&&mysql主从设置(多实例做多个主从)

一.源码安装mysql5.6.20 1.编译环境安装 yum install wget gcc* make openssl openssl-devel openssl-clients -y && yum groupinstall "Development Libraries" -y 2.源码下载(软件见Linux部署源码包) wget -P /usr/local/src/ http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.

MySQL多实例的安装

安装MySQL-5.5.49 安装包的获取:http://mirrors.sohu.com/mysql/ # 安装MySQL需要的依赖包 yum install ncurses-devel libaio-devel -y rpm -qa  ncurses-devel libaio-devel # 安装编译MySQL需要的软件 yum install cmake -y rpm -qa cmake # 创建用户 useradd mysql -u 777 -s /sbin/nologin -M id 

MySQL搭建系列之多实例

所谓多实例,就是在一台服务器上搭建.运行多个MySQL实例,每个实例使用不同的服务端口,通过不同的socket监听:物理上,每个实例拥有独立的参数配置文件及数据库. 通常情况下,一台服务器是不建议运行多个MySQL实例的,尤其是生产环境,因为这会造成资源相互强占问题.但在一些高可用环境中,却有这样的需求,比如:利用Heartbeat搭建的故障转移集群环境,若主备服务器只运行一个MySQL实例,则备用服务器平常处于闲置状态,造成了资源浪费:若各自运行一个MySQL实例,则在一方故障时,要求另一方接

Percona-XtraDB-Cluster的多实例编译安装

一.环境 CentOS release 6.9 Percona-XtraDB-Cluster-5.7.19-29.22.tar.gz boost_1_59_0.tar.gz percona-xtrabackup-24-2.4.7-1.el6.x86_64.rpm 节点 mysql服务端口 gmcast.listen端口 node01:192.168.1.210:6600 6600 6630 node02:192.168.1.210:6602 6602 6632 node03:gardb 无 55

MySQL之体系结构与存储实例

定义数据库和实例 在数据库领域中有两个词很容易混淆,这就是"数据库"(database)和"实例"(instance).作为常见的数据库术语,这两个词的定义如下: 数据库:物理操作系统文件或其他形式文件类型的集合.在MySQL数据库中,数据库文件可以是fm.MYD.MYI.ibd结尾的文件.当使用NDB引擎时,数据库的文件可能不是操作系统上的文件,而是存放在内存之中的文件,但是定义仍然不变. 实例:MySQL数据库由后台线程以及一个共享内存区组成.共享内存可以被运行

MySQL5.5多实例编译安装——多配置文件

一.什么是MySQL多实例?MySQL多实例简单的说就是在一台服务器上安装一套MySQL程序,通过不同的端口对外提供访问,多实例不仅节省物理主机成本,还有效提升了单台物理主机的CPU.磁盘I/O使用效率,而且还可以在多实例之间做部署数据库HA方案.二.如何配置MySQL多实例?配置mysql多实例有两种方式1.根据官方提供的是通过mysqld_multi使用单独的配置文件来实现多实例,这种方式定制每个实例的配置不太方面,优点是管理起来很方便,集中管理.2.使用多个配置文件和启动文件,配置文件之间

MySQL5.5多实例编译安装——mysqld_multi

一.MySQL多实例简介MySQL多实例,简单地说,就是在一台服务器上同时开启多个不同的服务端口(如:3306.3307),同时运行多个MySQL服务进程,这些服务进程通过不同的socket监听来自不同的端口来提供服务:多实例不仅节省物理主机成本,还有效提升了单台物理主机的CPU.磁盘I/O使用效率,而且还可以在多实例之间做部署数据库HA方案.随着实例数量的增加,就面临统一管理问题,这样我们就需要用MySQL自带的管理程序 mysqld_multi 来进行管理...二.MySQL启动流程mysq