LoginSignup
2
0

More than 5 years have passed since last update.

MySQLのパスワード初期化

Posted at

MySQLのパスワード初期化

見たサイト

作業ログ

root@hoge:~# mysqld_safe --init-file=/root/init-mysql
2017-08-26T02:11:59.477574Z mysqld_safe Logging to '/var/log/mysql/error.log'.
2017-08-26T02:11:59.492627Z mysqld_safe A mysqld process already exists
● mysql.service - MySQL Community Server
    Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
    Active: active (running) since Sat 2017-08-26 10:58:46 JST; 13min ago
    Process: 14792 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid (code=exited, status=0/SUCCESS)
    Process: 14752 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
    Main PID: 14798 (mysqld)
        CGroup: /system.slice/mysql.service
            └─14798 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

Aug 26 10:58:46 hoge systemd[1]: Starting MySQL Community Server...
Aug 26 10:58:46 hoge systemd[1]: Started MySQL Community Server.
root@hoge:~# systemctl stop mysql
root@hoge:~# mysqld_safe --init-file=/root/init-mysql
2017-08-26T02:12:19.986634Z mysqld_safe Logging to '/var/log/mysql/error.log'.
2017-08-26T02:12:19.988214Z mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists.
root@hoge:~# ls /var/run/mysqld
ls: cannot access '/var/run/mysqld': No such file or directory
root@hoge:~# mkdir -p /var/run/mysqld
root@hoge:~# chown mysql:mysql /var/run/mysqld/
root@hoge:~# mysqld_safe --init-file=/root/init-mysql
2017-08-26T02:13:05.628082Z mysqld_safe Logging to '/var/log/mysql/error.log'.
2017-08-26T02:13:05.641893Z mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
2017-08-26T02:13:07.52017-08-26T02:13:07.5201d 2017-08-26T02:13:07.52017-08-26T02:1.pid ended

上記方法ではどうしても上手く出来ないので方法を変えてみることにした。

mysqld_safe --skip-grant-tables --skip-networking &

ログイン出来たら...

mysql> use mysql;
mysql> update user set password=password("hogehoge123") where user='root';
ERROR 1054 (42S22): Unknown column 'password' in 'field list'
mysql> update user set authentication_string=password("hogehoge123") where user='root';
mysql> flush privileges;

起動させているプロセスを終了させる

ps aux | grep mysql

ユーザmysqlで起動しているプロセス探す

root@hoge:~# ps aux | grep mysql
root     16504  0.0  0.1   4508  1840 ?        S    12:07   0:00 /bin/sh /usr/bin/mysqld_safe --skip-grant-tables --skip-networking
mysql    16672  0.0 19.5 1260916 198308 ?      Sl   12:07   0:01 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin --user=mysql --skip-grant-tables --skip-networking --log-error=/var/log/mysql/error.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/run/mysqld/mysqld.sock
root     16953  0.0  0.1  14224  1028 pts/1    S+   12:48   0:00 grep --color=auto mysql

正常なプロセス終了の仕方が怪しかったので確認した。

オプションなしだとTERMだった。ダメ押しでオプション付けて終了させる。

kill -TERM 16672

プロセスが終了しているか確認

ps aux | grep mysql

新しく設定したパスワードで入れるか確かめる

mysql -u root -p

mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,ALTER,DROP,INDEX
    -> ON wp.*
    -> TO wp@localhost
    -> IDENTIFIED BY 'fugafuga456';
Query OK, 0 rows affected, 1 warning (0.01 sec)

Copyright (c) 2017 Tomoyuki KOYAMA
Released under the MIT license
http://opensource.org/licenses/mit-license.php

2
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
2
0