1
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?

More than 3 years have passed since last update.

mysql.server stopでフリーズする時の解決策

Last updated at Posted at 2020-12-09

先日、mariaDBサーバーを終了するために"$mysql.server stop"をターミナルで走らせたところ、実行後ターミナルがフリーズした問題が発生したので、その原因と解決策について書いておきます。

不具合

実行環境
・Mac OS Catalina 10.15
・MariaDB 10.5.8

$ mysql.server start
Starting MariaDB
.201209 18:59:04 mysqld_safe Logging to '/usr/local/var/mysql/your_user_name.local.err'.
201209 18:59:04 mysqld_safe Starting mariadbd daemon with databases from /usr/local/var/mysql
SUCCESS! 

$ mysql.server stop
# カーソルが点滅しフリーズ

状況

別ターミナルを開いて実行中のプロセスを確認してみる。

$ ps -ax | grep -e "mysql" -e "mariadb"
55377 ??         0:00.03 /bin/sh /usr/local/Cellar/mariadb/10.5.8/bin/mysqld_safe --datadir=/usr/local/var/mysql --pid-file=/usr/local/var/mysql/your_user_name.local.pid
55450 ??         0:00.74 /usr/local/Cellar/mariadb/10.5.8/bin/mariadbd --basedir=/usr/local/Cellar/mariadb/10.5.8 --datadir=/usr/local/var/mysql --plugin-dir=/usr/local/Cellar/mariadb/10.5.8/lib/plugin --log-error=/usr/local/var/mysql/your_user_name.local.err --pid-file=/usr/local/var/mysql/your_user_name.local.pid
56060 ttys000    0:00.01 grep -e mysql -e mariadb

sqlサーバーはに関連したプロセスがまだ残っていそう。

フリーズ中のターミナルのウインドウを閉じようとしてみると、、

スクリーンショット 2020-12-09 21.02.59.png

どうやらsh, suとやらが終わらないらしい。

原因

こちらの記事によると、mysql.server stop実行時に内部でsu_killというメソッドが呼ばれてるようなのですが、その時mysqlという名前のOSユーザーで実行することがデフォルトで設定されてるみたいで、mysqlという名前のユーザーがOS側にいないと停止できないみたいです。

解決策

一旦ターミナルのウインドウは閉じてしまって、killコマンドでプロセスを終了させましょう。

$ kill 55377
$ kill 55450

killのあとの数字はps -ax | grep -e "mysql" -e "mariadb"で出てきたプロセスIDを指定してください。

ユーザー名を確認します。

$echo $USER
> your_user_name

次に、/usr/local/bin/mysql.serverを編集します。

$ vi /usr/local/bin/mysql.server
/usr/local/bin/mysql.server
~
# user='mysql'
user='your_user_name'
~

元々あるuser='mysql'をコメントアウトし、echo $USERで返ってきたyour_user_nameを、新たにuser=で指定します。

$ mysql.server start
Starting MariaDB
.201209 21:15:51 mysqld_safe Logging to '/usr/local/var/mysql/your_user_name.err'.
201209 21:15:51 mysqld_safe Starting mariadbd daemon with databases from /usr/local/var/mysql
 SUCCESS! 
$ mysql.server stop
Shutting down MariaDB
. SUCCESS! 

終了することができました。

1
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
1
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?