yum 安装的mariadb_多实例

1. yum安装服务  

yum install mariadb-server

2. 创建多实例的目录

mkdir /mysqldb/{3306,3307,3308}/{etc,socket,pid,log,data} -pv
chown -R mysql.mysql /mysqldb/

3 生成数库文件

mysql_install_db --datadir=/mysqldb/3306/data --user=mysql --basedir=/usr
mysql_install_db --datadir=/mysqldb/3307/data --user=mysql --basedir=/usr
mysql_install_db --datadir=/mysqldb/3308/data --user=mysql --basedir=/usr

4 编辑配置文件 

cp /etc/my.cnf /mysqldb/3307/etc/
vim /mysqldb/3307/etc/my.cnf 
[root@centos7 3307]#cat etc/my.cnf 
[mysqld]
port=3307 ***
datadir=/mysqldb/3307/data
socket=/mysqldb/3307/socket/mysql.sock
symbolic-links=0
[mysqld_safe]
log-error=/mysqldb/3307/log/mariadb.log
pid-file=/mysqldb/3307/pid/mariadb.pid

5 编辑服务脚本 

vim /mysqldb/3307/mysqld
[root@db01 3306]# cat mysql 
#!/bin/bash
port=3306
mysql_user="root"
mysql_pwd="123456"
cmd_path="/usr/bin"
mysql_basedir="/mysqldb"
mysql_sock="${mysql_basedir}/${port}/socket/mysql.sock"

function_start_mysql(){
  if [ ! -e "$mysql_sock" ];then
    printf "Start 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 stoped...\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

6. 改权限 

chmod 700 /mysqldb/3307/mysqld
/mysqldb/3307/mysqld start

#查看端口
[root@db01 3306]# netstat -lntup|grep 330*
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 15422/mysqld 
tcp 0 0 0.0.0.0:3307 0.0.0.0:* LISTEN 15632/mysqld 
tcp 0 0 0.0.0.0:3308 0.0.0.0:* LISTEN 15802/mysqld

/mysqldb/3307/mysqld stop

 

6 改密码

mysqladmin -uroot -S /mysqldb/3307/socket/mysql.sock password '123456'
vim /mysqldb/3307/mysqld
# 将新的密码写入脚本中

7:重新启动

mysql -S /mysqldb/3307/socket/mysql.sock -uroot -p123456

 

posted @ 2019-11-22 19:18  堪舆先森  阅读(252)  评论(0编辑  收藏  举报