MySQLを起動しようとしたら、間違ったIPアドレスを見に行っていた問題

問題

mysqlを起動させようとしても、なぜか途中で起動が終わってしまう。

$ ps -ef | grep mysql
centos   27647 27403  0 11:55 pts/1    00:00:00 grep --color=auto mysql

mysqlが起動してないな。

$ sudo mysqld_safe
190611 11:54:28 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.
190611 11:54:29 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

あれ、起動が途中で終わっちゃう、、



状況確認

// エラーログファイルがどこにあるか確認
$ cat /etc/my.cnf
[client]
default-character-set=utf8

[mysql]
default-character-set=utf8

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
skip-character-set-client-handshake
character-set-server=utf8
character-set-client=utf8
init-connect = SET NAMES utf8
default_time_zone = '+0:00'

bind-address = 127.0.0.1
bind-address = 10.x.x.xxx

[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log  //←ココ
pid-file=/var/run/mariadb/mariadb.pid
timezone = UTC

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

// エラーログを確認
$ sudo cat /var/log/mariadb/mariadb.log
190611 11:28:43 [Note] Plugin 'FEEDBACK' is disabled.
190611 11:28:43 [Note] Server socket created on IP: '10.x.x.xxx'.
190611 11:28:43 [ERROR] Can't start server: Bind on TCP/IP port. Got error: 99: Cannot assign requested address
190611 11:28:43 [ERROR] Do you already have another mysqld server running on port: 3306 ?
190611 11:28:43 [ERROR] Aborting

3306のポートがすでに使われてるのか?

// 使っているポート確認
$ netstat -tanp
[client]
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      -
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      -
tcp6       0      0 :::111                  :::*                    LISTEN      -
tcp6       0      0 :::22                   :::*                    LISTEN      -
tcp6       0      0 ::1:25                  :::*                    LISTEN      -

特に3306は使ってなさげ、、

あれ、繋げてるIPアドレスがローカルじゃないぞ?

190611 11:28:43 [Note] Server socket created on IP: '10.x.x.xxx'. 

もう一度、my.cnfを確認

$ cat /etc/my.cnf
bind-address = 127.0.0.1
bind-address = 10.x.x.xxx

bind-adressが2つ存在してる。

調べてみたところ、bind-adressは複数設定できない。
複数行書くと、最後の行が使われるらしい。



解決

$ sudo vim /etc/my.cnf
bind-address = 127.0.0.1
# bind-address = 10.x.x.xxx //コメントアウトしておく

$ sudo mysqld_safe &
190611 11:54:28 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.
190611 11:54:29 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

$ ps -ef | grep mysql
root     27052  1951  0 11:54 pts/0    00:00:00 sudo mysqld_safe
root     27053 27052  0 11:54 pts/0    00:00:00 /bin/sh /bin/mysqld_safe
mysql    27293 27053  1 11:54 pts/0    00:00:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/run/mariadb/mariadb.pid --socket=/var/lib/mysql/mysql.sock
centos   27647 27403  0 11:55 pts/1    00:00:00 grep --color=auto mysql

やっとこさ起動できました。