Start and Stop multiple MySQL database server on local Mac
Tags: dbdb, database, mysql
Published: 2021-03-17 02:55:30

---
title: Start and Stop multiple MySQL database server on local Mac
published: true
description: Start and Stop multiple MySQL database server on local 
tags: dbdb, database, mysql
series: dbdb
//cover_image: https://direct_url_to_image.jpg
---

# Create my.cnf
```bash
cd ~/tmp/path-to-your-dir
touch mysql/versions/8.0.23/datadir/mysql8-name1/my.cnf
touch mysql/versions/8.0.23/datadir/mysql8-name2/my.cnf
touch mysql/versions/5.7.31/datadir/mysql5-name3/my.cnf
touch mysql/versions/5.7.31/datadir/mysql5-name4/my.cnf
```

# Start MySQL server with custom datadir and port
```bash
# MySQL 8.0.23 with port 13306
cd ~/tmp/path-to-your-dir
cd mysql/versions/8.0.23
dir=`pwd`
$dir/basedir/bin/mysqld \
 --defaults-extra-file=$dir/datadir/mysql8-name1/my.cnf \
 --daemonize \
 --user=_dbdb_mysql \
 --port=13306 \
 --socket=/tmp/dbdb_mysql_13306.sock \
 --basedir=$dir/basedir \
 --plugin-dir=$dir/basedir/lib/plugin  \
 --datadir=$dir/datadir/mysql8-name1 \
 --log-error=$dir/datadir/mysql8-name1/mysqld.err \
 --pid-file=$dir/datadir/mysql8-name1/mysql.pid

# MySQL 8.0.23 with port 23306
cd ~/tmp/path-to-your-dir
cd mysql/versions/8.0.23
dir=`pwd`
$dir/basedir/bin/mysqld \
 --defaults-extra-file=$dir/datadir/mysql8-name2/my.cnf \
 --daemonize \
 --user=_dbdb_mysql \
 --port=23306 \
 --socket=/tmp/dbdb_mysql_23306.sock \
 --basedir=$dir/basedir \
 --plugin-dir=$dir/basedir/lib/plugin  \
 --datadir=$dir/datadir/mysql8-name2 \
 --log-error=$dir/datadir/mysql8-name2/mysqld.err \
 --pid-file=$dir/datadir/mysql8-name2/mysql.pid

# MySQL 5.7.31 with port 33306
cd ~/tmp/path-to-your-dir
cd mysql/versions/5.7.31
dir=`pwd`
$dir/basedir/bin/mysqld \
 --defaults-extra-file=$dir/datadir/mysql5-name3/my.cnf \
 --daemonize \
 --user=_dbdb_mysql \
 --port=33306 \
 --socket=/tmp/dbdb_mysql_33306.sock \
 --basedir=$dir/basedir \
 --plugin-dir=$dir/basedir/lib/plugin  \
 --datadir=$dir/datadir/mysql5-name3 \
 --log-error=$dir/datadir/mysql5-name3/mysqld.err \
 --pid-file=$dir/datadir/mysql5-name3/mysql.pid

# MySQL 5.7.31 with port 43306
cd ~/tmp/path-to-your-dir
cd mysql/versions/5.7.31
dir=`pwd`
$dir/basedir/bin/mysqld \
 --defaults-extra-file=$dir/datadir/mysql5-name4/my.cnf \
 --daemonize \
 --user=_dbdb_mysql \
 --port=43306 \
 --socket=/tmp/dbdb_mysql_43306.sock \
 --basedir=$dir/basedir \
 --plugin-dir=$dir/basedir/lib/plugin  \
 --datadir=$dir/datadir/mysql5-name4 \
 --log-error=$dir/datadir/mysql5-name4/mysqld.err \
 --pid-file=$dir/datadir/mysql5-name4/mysql.pid
```

# Stop MySQL
```bash
# MySQL 8.0.23 with port 13306
cd ~/tmp/path-to-your-dir
cd mysql/versions/8.0.23
dir=`pwd`
$dir/basedir/bin/mysqladmin \
 --user=root \
 --host=localhost \
 --port=13306 \
 --socket=/tmp/dbdb_mysql_13306.sock \
 shutdown

# MySQL 8.0.23 with port 23306
cd ~/tmp/path-to-your-dir
cd mysql/versions/8.0.23
dir=`pwd`
$dir/basedir/bin/mysqladmin \
 --user=root \
 --host=localhost \
 --port=23306 \
 --socket=/tmp/dbdb_mysql_23306.sock \
 shutdown

# MySQL 5.7.31 with port 33306
cd ~/tmp/path-to-your-dir
cd mysql/versions/5.7.31
dir=`pwd`
$dir/basedir/bin/mysqladmin \
 --user=root \
 --host=localhost \
 --port=33306 \
 --socket=/tmp/dbdb_mysql_33306.sock \
 shutdown

# MySQL 5.7.31 with port 43306
cd ~/tmp/path-to-your-dir
cd mysql/versions/5.7.31
dir=`pwd`
$dir/basedir/bin/mysqladmin \
 --user=root \
 --host=localhost \
 --port=43306 \
 --socket=/tmp/dbdb_mysql_43306.sock \
 shutdown
```

# What's next?
- Connect MySQL
- or just try [dbdb](https://github.com/yuki777/dbdb).