码迷,mamicode.com
首页 > 其他好文 > 详细

实验:基于YUM安装的多实例

时间:2019-05-04 23:45:45      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:数据库   code   size   pid   tar   soc   yum   配置   dev   

实验:基于YUM安装的多实例

1.安装mariadb

yum install mariadb

2.创建多实例对应的目录结构

mkdir /mysql/{3306,3307,3308}/{data,,socket,log,bin,pid} -pv
技术图片
技术图片
chown -R mysql.mysql /mysql
技术图片

3.创建多实例的数据库文件

mysql_install_db --datadir=/mysql/3306/data/ --user=mysql
技术图片
mysql_install_db --datadir=/mysql/3307/data/ --user=mysql
mysql_install_db --datadir=/mysql/3308/data/ --user=mysql

4.创建对应配置文件

cp /etc/my.cnf /mysql/3306/etc
vim /mysql/3306/etc/my.cnf
[mysqld]
port=3306 加一行
datadir=/mysql/3306/data
socket=/mysql/3306/socket/mysql.sock
[mysqld_safe]
log-error=/mysql/3306/log/mariadb.log
pid-file=/mysql/3306/pid/mariadb.pid
技术图片

cp /mysql/3306/etc/my.cnf /mysql/3307/etc/my.cnf
/mysql/3307/etc/my.cnf
技术图片
技术图片
cp /mysql/3306/etc/my.cnf /mysql/3308/etc/my.cnf
/mysql/3308/etc/my.cnf
技术图片

5.准备各实例的启动脚本

vim /mysql/{3306,3307,3308}/bin/mysqld
cat /mysq/3306/bin/mysqld

#!/bin/bash  
port=3306  
mysql_user="root"  
mysql_pwd=" "  
cmd_path="/usr/bin"  
mysql_basedir="/mysql"  
mysql_sock="${mysql_basedir}/${port}/socket/mysql.sock"  

function_start_mysql()
{
    if [ ! -e "$mysql_sock" ];then
      printf "Starting MySQL...\n"
      ${cmd_path}/mysqld_safe --defaults-file=${mysql_basedir}/${port}/etc/my.cnf  &> /dev/null  &
    else
      printf "MySQL is running...\n"
      exit
    fi
}

function_stop_mysql()
{
    if [ ! -e "$mysql_sock" ];then
       printf "MySQL is stopped...\n"
       exit
    else
       printf "Stoping MySQL...\n"
       ${cmd_path}/mysqladmin -u ${mysql_user} -p${mysql_pwd} -S ${mysql_sock} shutdown
   fi
}

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: ${mysql_basedir}/${port}/bin/mysqld {start|stop|restart}\n"
esac

chmod +x /mysql/{3306,3307,3308}/bin/mysqld
技术图片

6.启动和关闭实例

/mysql/{3306,3307,3308}/bin/mysqld start
/mysql/{3306,3307,3308}/bin/mysqld stop
技术图片
记得更改脚本端口号

7.测试连接

mysql -S /mysql/{3306,3307,3308}/socket/mysql.sock
技术图片

8.安全加固

mysqladmin -S /mysql/{3306,3307,3308}/socket/mysql.sock password ‘centos‘
vim /mysql/{3306,3307,3308}/bin/mysqld 加上对应centos口令

实验:基于YUM安装的多实例

标签:数据库   code   size   pid   tar   soc   yum   配置   dev   

原文地址:https://blog.51cto.com/14234933/2388877

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!