はじめに
XAMPPをインストールしてmysqlを起動しようとしたが、mysqlが起動しませんでした。
色々試したが解決までに時間がかかったので備忘録です。
対象となる読者
xampp
mysql
起動しない
stop
などで必死にググっている方。
他の記事を一通り見たけど解決していない方。
結論
brewでinstallしたmysqlの自動起動設定が原因でした。
$ brew services list
Name Status User Plist
mysql@5.6 started xxxx /Users/xxxx/Library/LaunchAgents/homebrew.mxcl.mysql@5.6.plist
postgresql stopped
$ brew services stop mysql@5.6
Stopping `mysql@5.6`... (might take a while)
==> Successfully stopped `mysql@5.6` (label: homebrew.mxcl.mysql@5.6)
$ brew services list
Name Status User Plist
mysql@5.6 stopped
postgresql stopped
この状態でxamppのコントロールパネルからmysqlをstartすると無事に起動しました。
もしくはmac userの場合は sudo /Applications/XAMPP/xamppfiles/bin/mysql.server start
でもokです。
解決までのプロセス
まずはmysqlのXAMPPの中にあるmysqlのログファイルでなぜmysqlが起動しないのか調査しました。
macの場合は以下のコマンドでログファイルを起動できます。
$ sudo cat /Applications/XAMPP/xamppfiles/var/mysql/xxx.local.err
2021-10-17 19:37:58 4333 mysqld_safe Starting mysqld daemon with databases from /Applications/XAMPP/xamppfiles/var/mysql
2021-10-17 19:37:58 0 [Note] Using unique option prefix 'key_buffer' is error-prone and can break in the future. Please use the full name 'key_buffer_size' instead.
2021-10-17 19:37:58 0 [Note] /Applications/XAMPP/xamppfiles/sbin/mysqld (mysqld 10.4.21-MariaDB) starting as process 4485 ...
2021-10-17 19:37:58 0 [Warning] Setting lower_case_table_names=2 because file system for /Applications/XAMPP/xamppfiles/var/mysql/ is case insensitive
2021-10-17 19:37:58 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2021-10-17 19:37:58 0 [Note] InnoDB: Uses event mutexes
2021-10-17 19:37:58 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2021-10-17 19:37:58 0 [Note] InnoDB: Number of pools: 1
2021-10-17 19:37:58 0 [Note] InnoDB: Using SSE2 crc32 instructions
2021-10-17 19:37:58 0 [Note] InnoDB: Initializing buffer pool, total size = 16M, instances = 1, chunk size = 16M
2021-10-17 19:37:58 0 [Note] InnoDB: Completed initialization of buffer pool
2021-10-17 19:37:58 0 [Note] InnoDB: 128 out of 128 rollback segments are active.
2021-10-17 19:37:58 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2021-10-17 19:37:58 0 [Note] InnoDB: Setting file '/Applications/XAMPP/xamppfiles/var/mysql/ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2021-10-17 19:37:58 0 [Note] InnoDB: File '/Applications/XAMPP/xamppfiles/var/mysql/ibtmp1' size is now 12 MB.
2021-10-17 19:37:58 0 [Note] InnoDB: Waiting for purge to start
2021-10-17 19:37:58 0 [Note] InnoDB: 10.4.21 started; log sequence number 1764347; transaction id 2369
2021-10-17 19:37:58 0 [Note] InnoDB: Loading buffer pool(s) from /Applications/XAMPP/xamppfiles/var/mysql/ib_buffer_pool
2021-10-17 19:37:58 0 [Note] InnoDB: Buffer pool(s) load completed at 211017 19:37:58
2021-10-17 19:37:58 0 [Note] Plugin 'FEEDBACK' is disabled.
2021-10-17 19:37:58 0 [Note] Server socket created on IP: '::'.
2021-10-17 19:37:58 0 [ERROR] Can't start server: Bind on TCP/IP port. Got error: 48: Address already in use
2021-10-17 19:37:58 0 [ERROR] Do you already have another mysqld server running on port: 3306 ?
2021-10-17 19:37:58 0 [ERROR] Aborting
2021-10-17 19:38:00 4333 mysqld_safe mysqld from pid file /Applications/XAMPP/xamppfiles/var/mysql/xxxx.local.pid ended
ログの結果から見るに
2021-10-17 19:37:58 0 [ERROR] Can't start server: Bind on TCP/IP port. Got error: 48: Address already in use
2021-10-17 19:37:58 0 [ERROR] Do you already have another mysqld server running on port: 3306 ?
すでにmysqldがportの3306で起動していることが原因のよう。
port 3306を調べる
$ sudo lsof -i:3306
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mysqld 3745 xxxx 10u IPv4 0x2eb473aa2bf63d95 0t0 TCP localhost:mysql (LISTEN)
mysql周りで動作しているプロセスも確認しておく
$ ps aux | grep mysqld
xxxx 6508 0.0 0.0 4268424 728 s000 S+ 7:49PM 0:00.00 grep mysqld
xxxx 3745 0.0 0.1 4921796 19644 ?? S 7:36PM 0:00.50 /usr/local/opt/mysql@5.6/bin/mysqld --basedir=/usr/local/opt/mysql@5.6 --datadir=/usr/local/var/mysql --plugin-dir=/usr/local/opt/mysql@5.6/lib/plugin --log-error=xxxx.local.err --pid-file=xxxx.local.pid
xxxx 3645 0.0 0.0 4282204 892 ?? S 7:36PM 0:00.03 /bin/sh /usr/local/opt/mysql@5.6/bin/mysqld_safe --datadir=/usr/local/var/mysql
どうやら PID 3745のプロセスが原因っぽいのでプロセスをkillします。
$ kill 3745
プロセスがkillされたか確認する。
$ ps aux | grep mysqld
xxxx 6762 0.0 0.0 4268424 728 s000 S+ 7:51PM 0:00.00 grep mysqld
xxxx 6746 0.0 2.7 4931012 450596 ?? S 7:51PM 0:00.40 /usr/local/opt/mysql@5.6/bin/mysqld --basedir=/usr/local/opt/mysql@5.6 --datadir=/usr/local/var/mysql --plugin-dir=/usr/local/opt/mysql@5.6/lib/plugin --log-error=xxxx.err --pid-file=xxxx.pid
xxxx 6649 0.0 0.0 4282204 1184 ?? S 7:51PM 0:00.02 /bin/sh /usr/local/opt/mysql@5.6/bin/mysqld_safe --datadir=/usr/local/var/mysql
3745のプロセスはkill出来てるけど、同様のプロセスが6746で起動している?
port 3306で起動のプロセスを再度調べる
$ sudo lsof -i:3306
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mysqld 6746 xxxx 10u IPv4 0x2eb473aa39783a85 0t0 TCP localhost:mysql (LISTEN)
プロセスが殺せてない?もう一度指定のPIDでプロセスをkillする。
$ kill 6746
$ sudo lsof -i:3306
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mysqld 6932 xxxx 10u IPv4 0x2eb473aa37fff05d 0t0 TCP localhost:mysql (LISTEN)
また別のPIDでmysqldが起動している。そのため再度プロセスをkillする.
$ kill 6932
sudo lsof -i:3306
ここで3306のportは使用されてないことが確認されたので、mysqlをxamppで起動する。するとまたもや Do you already have another mysqld server running on port: 3306 ?
のエラーログが記録され、堂々巡りに陥る。
ここで、毎回mysqをPCの起動時に立ち上げる設定にしていたことを思い出す。mysqlはbrewでinstallしていたので、以下のコマンドでサービス一覧を確認する。
$ brew services list
Name Status User Plist
mysql@5.6 started xxxx /Users/xxxx/Library/LaunchAgents/homebrew.mxcl.mysql@5.6.plist
postgresql stopped
mysqlが自動起動するように設定されている。そのため、その設定を解除する。
$ brew services stop mysql@5.6
Stopping `mysql@5.6`... (might take a while)
==> Successfully stopped `mysql@5.6` (label: homebrew.mxcl.mysql@5.6)
再度サービス一覧を確認する。
$ brew services list
Name Status User Plist
mysql@5.6 stopped
postgresql stopped
サービスが起動していることを確認して、xamppのmysqlをstartさせると無事に起動しました。
ちなみにmysqldのプロセスを確認すると
ps aux | grep mysqld
_mysql 11015 0.0 0.1 4599456 10236 ?? S 8:07PM 0:01.59 /Applications/XAMPP/xamppfiles/sbin/mysqld --basedir=/Applications/XAMPP/xamppfiles --datadir=/Applications/XAMPP/xamppfiles/var/mysql --plugin-dir=/Applications/XAMPP/xamppfiles/lib/mysql/plugin/ --log-error=/Applications/XAMPP/xamppfiles/var/mysql/xxxx.local.err --pid-file=/Applications/XAMPP/xamppfiles/var/mysql/xxxx.local.pid --socket=/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock --port=3306
root 10863 0.0 0.0 4289372 680 ?? S 8:07PM 0:00.02 /bin/sh /Applications/XAMPP/xamppfiles/bin/mysqld_safe --datadir=/Applications/XAMPP/xamppfiles/var/mysql --pid-file=/Applications/XAMPP/xamppfiles/var/mysql/xxxxlocal.pid
xxxx 25510 0.0 0.0 4285832 760 s000 S+ 10:05PM 0:00.00 grep mysqld
無事にxamppのmysqlが起動していることが確認出来ました。やったね!