[DOCKER] Change Wordpress siteurl with command

Background

In order to repair a certain site, I built a Wordpress environment with Docker and launched it with localhost: 8000, but the CSS was not reflected and I had to change siteurl. The README of the repository described the procedure to change using "sequel pro", but "sequel pro, problem of not being able to connect!" Occurred. .. .. (It seems that the authentication method has changed when I saw Gugu) So instead of using sequencerpro, I decided to connect to Docker from the command and change siteurl. I rarely have the opportunity to touch this area, so I'd like to keep it as a memorandum!

Connect to Docker

sudo docker ps

When you execute the command, the container ID will be displayed, so check the container ID of the target DB described in docker-compose.yml. Then execute the following command

sudo docker exec -it {Container ID} /bin/bash

root @ container ID: / # If a prompt like this is displayed, the connection is successful! is.

Connect to DB

Check MYSQL_USER: and MYSQL_DATABASE: described in docker-compose.yml and execute the following command.

mysql -u {Database username} -p {Database name}

Then you will be prompted to enter {database password}, so enter the password listed in MYSQL_PASSWORD:.

Check settings

You can check the currently set seiteurl and home by executing the following command. Only siteurl should omit, "home" . (And vice versa)

select * from wp_options where option_name in ("siteurl","home");

Change settings

If you can confirm the current settings, change the settings.

update wp_options 
  set option_value="{Correct URL}"
 where option_name in ("siteurl");

If you want to change both seiteurl and home, make the last description as where option_name in ("siteurl", "home"); .

Check settings

Finally, make sure that you can change it properly and finish.

select * from wp_options where option_name in ("siteurl");

It is OK if the displayed siteurl is updated! Then, return to the TOP screen or management screen of the site and check that it is displayed properly.

Disconnect

Type exit in the command to disconnect from the DB and docker connections respectively.

As mentioned above, the trouble that suddenly occurs ...! !! It was a workaround for: fearful :!

reference

MySQL: When Sequel Pro cannot connect to MySQL How to restore when you accidentally change the site URL in WordPress general settings

Recommended Posts

Change Wordpress siteurl with command
Change seats with java
Change the port with SpringBoot
Execute external command with swift
WordPress with Docker Compose on CentOS 8
Create command line app with maven
Create a Maven project with a command