DEV Community

yuki777
yuki777

Posted on • Edited on

2 2

Start and Stop multiple MySQL database server on local Mac

Create my.cnf

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
Enter fullscreen mode Exit fullscreen mode

Start MySQL server with custom datadir and port

# 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
Enter fullscreen mode Exit fullscreen mode

Stop MySQL

# 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
Enter fullscreen mode Exit fullscreen mode

What's next?

  • Connect MySQL
  • or just try dbdb.

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Billboard image

Try REST API Generation for Snowflake

DevOps for Private APIs. Automate the building, securing, and documenting of internal/private REST APIs with built-in enterprise security on bare-metal, VMs, or containers.

  • Auto-generated live APIs mapped from Snowflake database schema
  • Interactive Swagger API documentation
  • Scripting engine to customize your API
  • Built-in role-based access control

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay