dora_shao

博客园 首页 新随笔 联系 订阅 管理

先简单介绍下,用docker安装的WordPress,mysql是在docker容器中的,并未在Ubuntu(我把WordPress是安装Ubuntu系统上),即WordPress和Ubuntu是独立的。所以,就算WordPress搭建好了,Ubuntu上也未安装mysql。

下面来说说怎么进入WordPress的数据库并做修改

  • docker-compose.yml文件中查看下mysql的username和password(按官网安装的WordPress是自己设置的)
    其中MYSQL_USER和MYSQL_PASSWORD冒号之后的即是我们需要的username和password
root@xxx:~# cat docker-compose.yml
version: '3.3'

services:
   db:
     *****
     ******
     environment:
       ******
       ******
       MYSQL_USER: ******
       MYSQL_PASSWORD: *****

   wordpress:
     ******
     ****
    db_data:
  • 查看mysql的container名,如下,container NAME是my_wordpress_db_1
root@xxx:~# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                  PORTS                  NAMES
b03f13a0c99a        wordpress:latest    "docker-entrypoint.s…"   3 days ago          Up 17 hours             0.0.0.0:8000->80/tcp   my_wordpress_wordpress_1
ef196d991832        mysql:5.7           "docker-entrypoint.s…"   3 days ago          Up 6 hours              3306/tcp               my_wordpress_db_1
82cf3b926ef2        hello-world         "/hello"                 4 days ago          Exited (0) 4 days ago                          hungry_villani
  • 连接到mysql的镜像中
root@xxx:~# docker exec -it my_wordpress_db_1 bash
root@ef196d991832:/#
  • 登陆mysql,username为之前在docker-compose.yml中查到的用户名,在Enter password弹出来时,再输入密码
root@ef196d991832:/# mysql -u username -p
Enter password: 
  • 查看database
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| wordpress          |
+--------------------+
2 rows in set (0.11 sec
  • 选中wordpress的database
USE wordpress
  • 查看wp_options表单(数据库的URL存在这里。)
mysql> select * from wp_options limit 2;
+-----------+-------------+---------------------+----------+
| option_id | option_name | option_value        | autoload |
+-----------+-------------+---------------------+----------+
|         1 | siteurl     | http://0.0.0.0:8000 | yes      |
|         2 | home        | http://0.0.0.0:8000 | yes      |
+-----------+-------------+---------------------+----------+
2 rows in set (0.00 sec)
  • 更改URL,其中your_wordpress_url是你的新URL,需要的URL
mysql> UPDATE wp_options SET option_value="your_wordpress_url" WHERE option_name="siteurl";
mysql> UPDATE wp_options SET option_value="your_wordpress_url" WHERE option_name="home";
posted on 2018-06-11 21:18  dora_shao  阅读(892)  评论(0编辑  收藏  举报