欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

mysql多实例的搭建

程序员文章站 2022-04-23 23:39:50
...

第一步 准备目录

[[email protected] /]# mkdir -p /data/330{7,8,9}/data

第二步 准备配置文件

  [[email protected] /]#cat > /data/3307/my.cnf <<EOF
    [mysqld]
    basedir=/application/mysql
    datadir=/data/3307/data
    socket=/data/3307/mysql.sock
    log_error=/data/3307/mysql.log
    port=3307
    server_id=7
    log_bin=/data/3307/mysql-bin
    EOF
    
 [[email protected] /]#cat > /data/3308/my.cnf <<EOF
    [mysqld]
    basedir=/application/mysql
    datadir=/data/3308/data
    socket=/data/3308/mysql.sock
    log_error=/data/3308/mysql.log
    port=3308
    server_id=8
    log_bin=/data/3308/mysql-bin
    EOF
    
 [[email protected] /]#cat > /data/3309/my.cnf <<EOF
    [mysqld]
    basedir=/application/mysql
    datadir=/data/3309/data
    socket=/data/3309/mysql.sock
    log_error=/data/3309/mysql.log
    port=3309
    server_id=9
    log_bin=/data/3309/mysql-bin
    EOF

第三步 初始化三套数据

[[email protected] /]# mv /etc/my.cnf /etc/my.cnf.bak
[[email protected] /]#mysqld --initialize-insecure  --user=mysql --datadir=/data/3307/data --basedir=/application/mysql
[[email protected] /]#mysqld --initialize-insecure  --user=mysql --datadir=/data/3308/data --basedir=/application/mysql
[[email protected] /]#mysqld --initialize-insecure  --user=mysql --datadir=/data/3309/data --basedir=/application/mysql

第四步 systemd管理多实例

   [[email protected] /]#cd /etc/systemd/system
   [[email protected] system]#cp mysqld.service mysqld3307.service
   [[email protected] system]#cp mysqld.service mysqld3308.service
   [[email protected] system]#cp mysqld.service mysqld3309.service

分别改以下三个文件里的内容:

[[email protected] system]#vim mysqld3307.service
[[email protected] system]#vim mysqld3308.service
[[email protected] system]#vim mysqld3309.service

修改的选项为:

ExecStart=/app/mysql/bin/mysqld  --defaults-file=/data/3307/my.cnf
ExecStart=/app/mysql/bin/mysqld  --defaults-file=/data/3308/my.cnf
ExecStart=/app/mysql/bin/mysqld  --defaults-file=/data/3309/my.cnf

第五步 授权数据文件

[[email protected] /]# chown -R mysql.mysql /data/*

第六步 启动多实例

  [[email protected] /]#netstat -lnp|grep 330
  [[email protected] /]#mysql -S /data/3307/mysql.sock -e "select @@server_id"
  [[email protected] /]#mysql -S /data/3308/mysql.sock -e "select @@server_id"
  [[email protected] /]#mysql -S /data/3309/mysql.sock -e "select @@server_id"
相关标签: mysql学习