MySQL/MariaDBとサービス/サーバの起動・停止方法

MySQL、MariaDBのサービスの起動・停止方法を紹介します。

パッケージからインストールした場合とmakeした場合にどちらも対応しているので参考にしてみてください。

なお今回の記事はMariaDBで実行して確認をしています。

目次

サービス/サーバの起動:mysqld_safe

サービスを起動するには「mysqld_safe」コマンドを利用します。

「mysqld_safe」はバックグランドで起動する必要があります。

mysqld_safe <オプション> &

「mysqld_safe」は実行時に設定ファイル「/etc/my.cnf」を読み込みます。

以下実行ログです。

$ mysqld_safe &
181110 03:27:06 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.
181110 03:27:06 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

サービス/サーバの停止:mysqladmin shutdown

サービスを起動するには「mysqladmin shutdown」コマンドを利用します。

mysqladmin <オプション> shutdown

「mysqladmin shutdown」にはデータベースユーザにSHUTDOWN権限が必要です。

以下が実行ログです。

# mysqladmin -u root -p shutdown
Enter password:
[1]+ Done mysqld_safe

パッケージインストールした場合の起動/停止:systemctl

パッケージからインストールした時は「systemctl」コマンドを利用できます。

起動は以下のコマンドを利用します。

systemctl start <MySQLorMariaDBのサービス>

停止は以下のコマンドを利用します。

systemctl stop <MySQLorMariaDBのサービス>

以下が実行例になります。

$ systemctl start mariadb.service

$ systemctl status mariadb.service

● mariadb.service - MariaDB database server

   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)

   Active: active (running) since Sat 2018-11-10 03:44:55 JST; 2s ago

  Process: 21281 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=0/SUCCESS)

  Process: 21249 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SUCCESS)

 Main PID: 21280 (mysqld_safe)

   CGroup: /system.slice/mariadb.service

           tq21280 /bin/sh /usr/bin/mysqld_safe --basedir=/usr

           mq21454 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysq...

Nov 10 03:44:53 test-server systemd[1]: Starting MariaDB database server...
Nov 10 03:44:53 test-server mariadb-prepare-db-dir[21249]: Database MariaDB is probably initialized in /...ne.
Nov 10 03:44:53 test-server mariadb-prepare-db-dir[21249]: If this is not the case, make sure the /var/l...ir.
Nov 10 03:44:53 test-server mysqld_safe[21280]: 181110 03:44:53 mysqld_safe Logging to '/var/log/mariad...og'.
Nov 10 03:44:53 test-server mysqld_safe[21280]: 181110 03:44:53 mysqld_safe Starting mysqld daemon with...ysql
Nov 10 03:44:55 test-server systemd[1]: Started MariaDB database server.
Hint: Some lines were ellipsized, use -l to show in full.
$ systemctl stop mariadb.service
$ systemctl status mariadb.service
● mariadb.service - MariaDB database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
Active: inactive (dead) since Sat 2018-11-10 03:45:04 JST; 1s ago
Process: 21281 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=0/SUCCESS)
Process: 21280 ExecStart=/usr/bin/mysqld_safe --basedir=/usr (code=exited, status=0/SUCCESS)
Process: 21249 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SUCCESS)
Main PID: 21280 (code=exited, status=0/SUCCESS)

Nov 10 03:44:53 test-server systemd[1]: Starting MariaDB database server...
Nov 10 03:44:53 test-server mariadb-prepare-db-dir[21249]: Database MariaDB is probably initialized in /...ne.
Nov 10 03:44:53 test-server mariadb-prepare-db-dir[21249]: If this is not the case, make sure the /var/l...ir.
Nov 10 03:44:53 test-server mysqld_safe[21280]: 181110 03:44:53 mysqld_safe Logging to '/var/log/mariad...og'.
Nov 10 03:44:53 test-server mysqld_safe[21280]: 181110 03:44:53 mysqld_safe Starting mysqld daemon with...ysql
Nov 10 03:44:55 test-server systemd[1]: Started MariaDB database server.
Nov 10 03:45:02 test-server systemd[1]: Stopping MariaDB database server...
Nov 10 03:45:04 test-server systemd[1]: Stopped MariaDB database server.
Hint: Some lines were ellipsized, use -l to show in full.
よかったらシェアしてね!
  • URLをコピーしました!
目次