Help us understand the problem. What is going on with this article?

MySQLのパスワード初期化

More than 1 year has passed since last update.

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

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

http://kazmax.zpp.jp/linux_beginner/process_kill.html

オプションなしだと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

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした