Dockerで動いているWordpressでWordpressアドレスやサイトアドレスをうっかり間違えて更新してしまい管理画面にアクセスできなくなった時の復旧方法です。
DBはMySQLです。
sshでlinuxに入る。
root@xxxxxxxxxxxxx:~/wordpress# docker exec -it {MySQLのコンテナのNAME} bash
bash-4.2# mysql -u {MySQLのユーザ名} -p
Enter password:{MySQLユーザのパスワード}
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is nnnn
Server version: 5.7.39 MySQL Community Server (GPL)
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| wordpress |
+--------------------+
2 rows in set (0.00 sec)
mysql> use wordpress
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select * from wp_options where option_name in ('siteurl', 'home');
+-----------+-------------+-----------------------+----------+
| option_id | option_name | option_value | autoload |
+-----------+-------------+-----------------------+----------+
| 2 | home | {間違っているhome} | yes |
| 1 | siteurl | {間違っているsiteurl} | yes |
+-----------+-------------+-----------------------+----------+
2 rows in set (0.00 sec)
mysql> update wp_options set option_value = '{正しいhome}' where option_name = 'home';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> update wp_options set option_value = '{正しいsiteurl}' where option_name = 'siteurl';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> commit;
Query OK, 0 rows affected (0.00 sec)
mysql> \q
Bye
上ではcommitしているが、start transactionしていないのでupdateが即反映されている。commitは不要。
