0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

MySQLの起動・停止・再起動コマンド(Windows & Mac)

Last updated at Posted at 2025-03-26

はじめに

開発や学習でMySQLを使っていると、「手動で起動したい」「再起動したいけどどうやるの?」という場面が必ず出てきます。
この記事では、Windows / macOS の両方で使える MySQL の基本操作コマンド(起動・停止・再起動)をまとめました。

方法①:ターミナル / コマンドプロンプトから操作

Windows の場合

起動

初めて起動する前にmysqld --initializeが必要な場合もあります。

cd "C:\Program Files\MySQL\MySQL Server 8.0\bin"
mysqld

停止

サーバーが起動中で、rootユーザーに適切なパスワードが設定されている必要があります。

mysqladmin -u root -p shutdown

再起動

MySQL には「再起動コマンド」はないため、手動で以下のように実行します。

mysqladmin -u root -p shutdown
mysqld

macOS の場合(Homebrewインストール前提)

起動

brew services start mysql

停止

brew services stop mysql

再起動

brew services restart mysql

※Homebrew 経由でMySQLをインストールしていない場合

# 起動
mysql.server start

# 停止
mysql.server stop

# 再起動
mysql.server restart

方法②:GUIから操作

Windows:サービス(services.msc)

  1. Win + R → services.msc と入力
  2. MySQL80 や MySQL を探す
  3. 右クリックして「開始」「停止」「再起動」が可能

macOS:システム環境設定(MySQLアイコン)

/Applications/System Preferences にあるMySQLパネルから起動・停止が可能
※インストール方法による

方法③:バッチ・スクリプトで効率化

スクリプトとして保存しておけば、1コマンドでサーバー操作ができます。

Windows

:: start_mysql.bat
cd "C:\Program Files\MySQL\MySQL Server 8.0\bin"
start mysqld

macOS

#!/bin/bash
brew services restart mysql

トラブルシューティング(起動しないときの原因と対処)

起動時にエラー:Failed to set datadir

[ERROR] Failed to set datadir to 'C:\Program Files\MySQL\MySQL Server 8.0\data\'

原因 → data ディレクトリが存在しない or 権限不足
対処 → 初期化

mysqld --initialize --console

ポート3306が使用中

Can't bind to port 3306

対処法
→ タスクマネージャー(またはlsof -i :3306)で競合アプリを確認
→ my.cnf や my.ini でポートを変更

おわりに

MySQL の起動や再起動は、開発環境でトラブルが起きたときや、設定を変更した際に使用します。
GUIだけでなくコマンド操作にも慣れておくと、作業がスムーズに進むと思います!
ご参考になれば幸いです。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?