Create multiple MySQL database server on local Mac
Tags: dbdb, database, mysql
Published: 2021-03-17 02:50:55

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

# Description
- This section explains how to create multiple mysql servers locally.
- However, if you don't want to read that already, you can use [dbdb](https://github.com/yuki777/dbdb).

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xxamek8nczqmzvk7ddfz.png)

# Download
- First of all, Let's download MySQL source from [mysql.com](https://dev.mysql.com/downloads/mysql/)
- Choose one or two what you want to use.

# Install MySQL
- Extract mysql source into separated directory for each version.
```bash
# 8.0.23
mkdir -p ~/tmp/path-to-your-dir
cd       ~/tmp/path-to-your-dir
mkdir -p mysql/versions/8.0.23/basedir
cd mysql/versions/8.0.23/basedir
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.23-macos10.15-x86_64.tar.gz
tar zxf mysql-8.0.23-macos10.15-x86_64.tar.gz --strip-components 1

# 5.7.31
mkdir -p ~/tmp/path-to-your-dir
cd       ~/tmp/path-to-your-dir
mkdir -p mysql/versions/5.7.31/basedir
cd mysql/versions/5.7.31/basedir
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.31-macos10.14-x86_64.tar.gz
tar zxf mysql-5.7.31-macos10.14-x86_64.tar.gz --strip-components 1
```

# Initialize MySQL server with custom datadir and port
- [MySQL 8.0 server options](https://dev.mysql.com/doc/refman/8.0/en/server-options.html)
- [MySQL 5.7 server options](https://dev.mysql.com/doc/refman/5.7/en/server-options.html)
- By separating the socket and port, each mysql can be started as a separate process.
```bash
# MySQL 8.0.23 with port 13306
cd ~/tmp/path-to-your-dir
mkdir -p mysql/versions/8.0.23/datadir/mysql8-name1
cd mysql/versions/8.0.23
dir=`pwd`
$dir/basedir/bin/mysqld \
  --initialize-insecure \
  --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
mkdir -p mysql/versions/8.0.23/datadir/mysql8-name2
cd mysql/versions/8.0.23
dir=`pwd`
$dir/basedir/bin/mysqld \
  --initialize-insecure \
  --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
mkdir -p mysql/versions/5.7.31/datadir/mysql5-name3
cd mysql/versions/5.7.31
dir=`pwd`
$dir/basedir/bin/mysqld \
  --initialize-insecure \
  --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
mkdir -p mysql/versions/5.7.31/datadir/mysql5-name4
cd mysql/versions/5.7.31
dir=`pwd`
$dir/basedir/bin/mysqld \
  --initialize-insecure \
  --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
```

# What's next?
- Start multiple MySQL database server on local Mac
- or just use [dbdb](https://github.com/yuki777/dbdb).