CentOS7環境にmysqlを導入しmysqld_safe
を使おうと思ったら
[root@mysql-server ~]# mysqld_safe -bash: mysqld_safe: コマンドが見つかりません
とでました。
MySQL :: MySQL 5.7 Reference Manual :: 2.5.10 Managing MySQL Server with systemd より
Note On platforms for which systemd support for MySQL is installed, scripts such as mysqld_safe and the System V initialization script are unnecessary and are not installed. For example, mysqld_safe can handle server restarts, but systemd provides the same capability, and does so in a manner consistent with management of other services rather than by using an application-specific program. Because systemd has the capability of managing multiple MySQL instances on platforms for which systemd support for MySQL is installed, mysqld_multi and mysqld_multi.server are unnecessary and are not installed.
どうやらsystemdな環境ではmysqld_safe
はインストールされないようです。
同リンクの Configuring systemd for MySQL
にやり方が書いてありました。
systemdの環境変数を利用する
systemdを使う環境ではmysqld_safe
ではなく、systemdの環境変数を用いるようです。
具体的には systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"
を実行してmysqldを再起動すればOK。
[root@mysql-server ~]# systemctl set-environment MYSQLD_OPTS="--skip-grant-tables" [root@mysql-server ~]# systemctl restart mysqld [root@mysql-server ~]# systemctl status mysqld ● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since 木 2020-12-03 18:19:18 JST; 6s ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Process: 14706 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS) Process: 14684 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS) Main PID: 14710 (mysqld) CGroup: /system.slice/mysqld.service └─14710 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid --skip-grant-tables 12月 03 18:19:17 mysql-server systemd[1]: Stopped MySQL Server. 12月 03 18:19:17 mysql-server systemd[1]: Starting MySQL Server... 12月 03 18:19:18 mysql-server systemd[1]: Started MySQL Server.
こんなふうに --skip-grant-tables
と付きます。
Main PID: 14710 (mysqld) CGroup: /system.slice/mysqld.service └─14710 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid --skip-grant-tables
あとは mysql -u root
などでログインできます。
戻し方
systemctl unset-environment MYSQLD_OPTS
と実行してmysqldを再起動すればOKです。
[root@mysql-server ~]# systemctl unset-environment MYSQLD_OPTS [root@mysql-server ~]# systemctl restart mysqld [root@mysql-server ~]# systemctl status mysqld ● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since 木 2020-12-03 18:20:23 JST; 1s ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Process: 14903 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS) Process: 14880 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS) Main PID: 14906 (mysqld) CGroup: /system.slice/mysqld.service └─14906 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid 12月 03 18:20:21 mysql-server systemd[1]: Stopped MySQL Server. 12月 03 18:20:21 mysql-server systemd[1]: Starting MySQL Server... 12月 03 18:20:23 mysql-server systemd[1]: Started MySQL Server. [root@mysql-server ~]#