小编给大家分享一下关系型数据库数据库多实例配置的示例分析,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!
二进制安装:
[root @陆丰centos ~]# mkdir/home/陆丰/tools-p
【根@陆丰centos ~】#光盘/首页/陆丰/工具
[root@lufengcentostools]#rz
[root @ lufengcentostools]# tarxfmysql-5。5 .49-Linux 2.6-x86 _ 64。焦油。地面零点
[root @ lufengcentostools]# mkdir-p/application/MySQL-5。5 .49
[root @ lufengcentostools]# mvmysql-5。5 .49-Linux 2.6-x86 _ 64/应用/MySQL-5。5 .49
创建关系型数据库用户|组
[root @ lufengcentostools]# group addmysql
[root @ lufengcentostools]# user addmysql-gmysql-s/sbin/nologin-M
[root @ lufengcentostools]# ln-s/application/MySQL-5。5 .49//应用程序/MySQL
root@lufengcentosmysql]#sed-i的#/usr/local/MySQL #/application/MySQL # g '/application/MySQL/bin/MySQL _ safe
创建多实例数据文件目录
[root @ MySQL-server _ 2 ~]# mkdir-p/data/{ 3306,3307}/data
配置相应的配置文件:
[root @ MySQL-server _ 2 ~]# cat/data/3306/my。CNF
####################################################
[客户]
#密码=您的_密码
端口=3306
socket=/data/3306/mysql.sock
[mysqld]
用户=mysql
端口=3306
socket=/data/3306/mysql.sock
basedir=/application/mysql
datadir=/data/3306/data
pid-file=/data/3306/mysql.pid
中继日志=/数据/3306/中继箱
中继-日志-信息-文件=/数据/3306/中继-日志。信息
跳跃外部锁定
key_buffer_size=16K
最大允许数据包=1M
table_open_cache=4
排序缓冲区大小
= 64K
read_buffer_size = 256K
read_rnd_buffer_size = 256K
net_buffer_length = 2K
thread_stack = 128K
server-id = 1
[mysqldump]
quick
max_allowed_packet = 2M
[mysql]
no-auto-rehash
[mysql_safe]
log-error=/data/3306/mysql_lufeng3306.err
pid-file=/data/3306/mysqlf.pid
##############################################
[root@Mysql-server_2 ~]# cat /data/3307/my.cnf
#############################################
[client]
#password = your_password
port = 3307
socket = /data/3307/mysql.sock
[mysqld]
user = mysql
port = 3307
socket = /data/3307/mysql.sock
basedir = /application/mysql
datadir = /data/3307/data
pid-file = /data/3307/mysql.pid
relay-log = /data/3307/relay-bin
relay-log-info-file = /data/3307/relay-log.info
skip-external-locking
key_buffer_size = 16K
max_allowed_packet = 1M
table_open_cache = 4
sort_buffer_size = 64K
read_buffer_size = 256K
read_rnd_buffer_size = 256K
net_buffer_length = 2K
thread_stack = 128K
server-id = 2
[mysqldump]
quick
max_allowed_packet = 2M
[mysql]
no-auto-rehash
[mysql_safe]
log-error=/data/3307/mysql_lufeng3307.err
pid-file=/data/3307/mysqlf.pid
##############################################
创建启动文件
[root@Mysql-server_2 ~]# cat /data/3306/mysql
#!/bin/sh
################################
#mysql 3306 by lufeng @2017.4.3
################################
#int
port=3306
mysql_user="root"
mysql_pwd="199429"
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
##########################################################
[root@Mysql-server_2 ~]# cat /data/3307/mysql
#!/bin/sh
################################
#mysql 3307 by lufeng @2017.4.3
################################
#int
port=3307
mysql_user="root"
mysql_pwd="199429"
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
#######################################################
配置多实例文件权限
[root@Mysql-server_2 ~]# chown -R mysql.mysql /data
[root@Mysql-server_2 ~]# find /data -name mysql|xargs chmod 700
[root@Mysql-server_2 ~]# find /data -name mysql -exec ls -l {} \;
-rwx------ 1 mysql mysql 999 4月 3 13:33 /data/3306/mysql
-rwx------ 1 mysql mysql 1210 4月 3 13:35 /data/3307/mysql
全局变量:
[root@Mysql-server_2 ~]# ls /application/mysql/bin/mysql
/application/mysql/bin/mysql
[root@Mysql-server_2 ~]# echo 'export PATH=/application/mysql/bin:$PATH' >>/etc/profile
[root@Mysql-server_2 ~]# tail -1 /etc/profile
export PATH=/application/mysql/bin:$PATH
[root@Mysql-server_2 ~]# source /etc/profile
[root@Mysql-server_2 ~]# echo $PATH
/application/mysql/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
初始化数据库文件
[root@Mysql-server_2 scripts]# cd /application/mysql/scripts/
[root@Mysql-server_2 scripts]# ./mysql_install_db --basedir=/application/mysql --datadir=/data/3306/data --user=mysql
[root@Mysql-server_2 scripts]# ./mysql_install_db --basedir=/application/mysql --datadir=/data/3307/data --user=mysql
Installing MySQL system tables...
170403 13:47:58 [Note] /application/mysql/bin/mysqld (mysqld 5.5.49) starting as process 2971 ...
OK
Filling help tables...
170403 13:47:59 [Note] /application/mysql/bin/mysqld (mysqld 5.5.49) starting as process 2980 ...
OK
============成功标志
启动命令:
[root@Mysql-server_2 ~]# /data/3306/mysql start
Starting MySQL...
[root@Mysql-server_2 ~]# /data/3307/mysql start
Starting MySQL...
[root@Mysql-server_2 ~]# netstat -lntup|grep mysql
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 3638/mysqld
tcp 0 0 0.0.0.0:3307 0.0.0.0:* LISTEN 3962/mysqld
配置开机自启动:
[root@Mysql-server_2 ~]# echo "mysql multi instances" >>/etc/rc.local
[root@Mysql-server_2 ~]# echo "/data/3306/mysql start" >>/etc/rc.local
[root@Mysql-server_2 ~]# echo "/data/3307/mysql start" >>/etc/rc.local
[root@Mysql-server_2 ~]# tail -3 /etc/rc.local
mysql multi instances
/data/3306/mysql start
/data/3307/mysql start
登录:[root@lufengcentos ~]# mysql -S /data/3306/mysql.sock
安全配置:
[root@lufengcentos ~]# mysqladmin -u root -S /data/3307/mysql.sock password '199429'
[root@lufengcentos ~]# mysql -S /data/3306/mysql.sock -uroot -p
Enter password:
看完了这篇文章,相信你对“Mysql数据库多实例配置的示例分析”有了一定的了解,如果想了解更多相关知识,欢迎关注行业资讯频道,感谢各位的阅读!
内容来源网络,如有侵权,联系删除,本文地址:https://www.230890.com/zhan/102731.html