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账号

   [root@192 ~]# groupadd mysql

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

 

  创建完成之后查看下

   [root@192 ~]# grep mysql /etc/passwd

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


 1.2建立mysql的安装目录

   [root@192 ~]# mkdir -p /usr/local/mysql

   [root@192 ~]# mkdir -p /data/mysql/data

   


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



2;安装mysql

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

      [root@taoke1 ~]# 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并安装 

[root@taoke1 ~]# tar xzvf mysql-5.5.37.tar.gz

[root@taoke1 ~]# 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 \       #套接字文件

[root@taoke1 mysql-5.6.23]# make && make install



3;初始化数据库

[root@xiangys02 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=\\u@\\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=\\u@\\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;定义全局

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

[root@xiangys01 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;登陆

[root@xiangys01 3307]# /usr/local/mysql/bin/mysql -uroot -p -S /data/mysql/data/3306/mysql.sock

[root@xiangys01 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;启动脚本编写

[root@xiangys01 3306]# vi mysqld

[root@xiangys01 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


[root@xiangys01 3307]# /data/mysql/data/3306/mysqld restart

Stoping MySQL...

Starting MySQL...

[root@xiangys01 3307]# /data/mysql/data/3307/mysqld restart

Stoping MySQL...

Starting MySQL...



9;开机自启动mysql

[root@xiangys01 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









   


你可能感兴趣的:(mysql-5.5.37多实例)