簡體   English   中英

Wordpress Docker“建立數據庫連接時出錯”

[英]Wordpress Docker "Error establishing a database connection"

我已經根據本教程設置了一個服務器來托管多個網站: https ://blog.ssdnodes.com/blog/host-multiple-ssl-websites-docker-nginx/

我還為 wordpress 配置了 docker-compose.yml,就像他們在同一教程中的示例 2 中所做的那樣。 但是當我打開網站時,我收到“建立數據庫連接時出錯”錯誤。 我記得幾個月前在一切正常的情況下這樣做,但我不記得我做了什么不同的事情。

這是我在輸入 docker-compose up 后收到的錯誤消息(多次)

wp_test           | MySQL Connection Error: (1045) Access denied for user 'wordpress'@'172.20.0.9' (using password: YES)
wp_test_db        | 2020-02-23T21:00:45.772510Z 11 [Note] Access denied for user 'wordpress'@'172.20.0.9' (using password: YES)

我的 docker-compose.yml 文件如下所示:

version: "3"

services:
   db_node_domain:
     image: mysql:5.7
     volumes:
        - db_data:/var/lib/mysql
     restart: always
     environment:
        MYSQL_ROOT_PASSWORD: somewordpress
        MYSQL_DATABASE: wordpress
        MYSQL_USER: wordpress
        MYSQL_PASSWORD: wordpress
     container_name: wp_test_db

   wordpress:
     depends_on:
        - db_node_domain
     image: wordpress:latest
     expose:
        - 80
     restart: always
     environment:
        VIRTUAL_HOST: blog.example.com
        LETSENCRYPT_HOST: blog.example.com
        LETSENCRYPT_EMAIL: foo@example.com
        WORDPRESS_DB_HOST: db_node_domain:3306
        WORDPRESS_DB_USER: wordpress
        WORDPRESS_DB_PASSWORD: wordpress
     container_name: wp_test
volumes:
  db_data:

networks:
  default:
    external:
      name: nginx-proxy

我試圖停止並啟動圖像,如下所示: https ://www.reddit.com/r/docker/comments/ahzv5d/wordpress_cant_connect_to_mysql/

我還嘗試了另一個 wordpress docker-config.yml 並添加了我自己的 nginx 參數,但得到了相同的錯誤消息https://docs.docker.com/compose/wordpress/

編輯我收到新的錯誤消息

wp_test_db        | 2020-02-23T22:09:40.654580Z 0 [Note] mysqld (mysqld 5.7.29) starting as process 1 ...
wp_test_db        | 2020-02-23T22:09:40.659627Z 0 [Note] InnoDB: PUNCH HOLE support available
wp_test_db        | 2020-02-23T22:09:40.659883Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
wp_test_db        | 2020-02-23T22:09:40.659958Z 0 [Note] InnoDB: Uses event mutexes
wp_test_db        | 2020-02-23T22:09:40.660412Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
wp_test_db        | 2020-02-23T22:09:40.660451Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
wp_test_db        | 2020-02-23T22:09:40.660811Z 0 [Note] InnoDB: Using Linux native AIO
wp_test_db        | 2020-02-23T22:09:40.661814Z 0 [Note] InnoDB: Number of pools: 1
wp_test_db        | 2020-02-23T22:09:40.662418Z 0 [Note] InnoDB: Using CPU crc32 instructions
wp_test_db        | 2020-02-23T22:09:40.667522Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
wp_test_db        | 2020-02-23T22:09:40.681674Z 0 [Note] InnoDB: Completed initialization of buffer pool
wp_test_db        | 2020-02-23T22:09:40.687033Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
wp_test_db        | 2020-02-23T22:09:40.701423Z 0 [ERROR] [FATAL] InnoDB: Table flags are 0 in the data dictionary but the flags in file ./ibdata1 are 0x4000!
wp_test_db        | 2020-02-23 22:09:40 0x7f7ce62ee740  InnoDB: Assertion failure in thread 140174414505792 in file ut0ut.cc line 918
wp_test_db        | InnoDB: We intentionally generate a memory trap.
wp_test_db        | InnoDB: Submit a detailed bug report to http://bugs.mysql.com.
wp_test_db        | InnoDB: If you get repeated assertion failures or crashes, even
wp_test_db        | InnoDB: immediately after the mysqld startup, there may be
wp_test_db        | InnoDB: corruption in the InnoDB tablespace. Please refer to
wp_test_db        | InnoDB: http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html
wp_test_db        | InnoDB: about forcing recovery.
wp_test_db        | 22:09:40 UTC - mysqld got signal 6 ;
wp_test_db        | This could be because you hit a bug. It is also possible that this binary
wp_test_db        | or one of the libraries it was linked against is corrupt, improperly built,
wp_test_db        | or misconfigured. This error can also be caused by malfunctioning hardware.
wp_test_db        | Attempting to collect some information that could help diagnose the problem.
wp_test_db        | As this is a crash and something is definitely wrong, the information
wp_test_db        | collection process might fail.
wp_test_db        | 
wp_test_db        | key_buffer_size=8388608
wp_test_db        | read_buffer_size=131072
wp_test_db        | max_used_connections=0
wp_test_db        | max_threads=151
wp_test_db        | thread_count=0
wp_test_db        | connection_count=0
wp_test_db        | It is possible that mysqld could use up to 
wp_test_db        | key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 68196 K  bytes of memory
wp_test_db        | Hope that's ok; if not, decrease some variables in the equation.
wp_test_db        | 
wp_test_db        | Thread pointer: 0x0
wp_test_db        | Attempting backtrace. You can use the following information to find out
wp_test_db        | where mysqld died. If you see no messages after this, something went
wp_test_db        | terribly wrong...
wp_test_db        | stack_bottom = 0 thread_stack 0x40000
wp_test_db        | mysqld(my_print_stacktrace+0x2c)[0x5643574c60cc]
wp_test_db        | mysqld(handle_fatal_signal+0x479)[0x564356de87b9]
wp_test_db        | /lib/x86_64-linux-gnu/libpthread.so.0(+0x110e0)[0x7f7ce5ecb0e0]
wp_test_db        | /lib/x86_64-linux-gnu/libc.so.6(gsignal+0xcf)[0x7f7ce4657fff]
wp_test_db        | /lib/x86_64-linux-gnu/libc.so.6(abort+0x16a)[0x7f7ce465942a]
wp_test_db        | mysqld(+0x699b25)[0x564356dbeb25]
wp_test_db        | mysqld(_ZN2ib5fatalD1Ev+0x12d)[0x56435782ed8d]
wp_test_db        | mysqld(+0x11b68f1)[0x5643578db8f1]
wp_test_db        | mysqld(+0x11b6f28)[0x5643578dbf28]
wp_test_db        | mysqld(_Z6fil_ioRK9IORequestbRK9page_id_tRK11page_size_tmmPvS8_+0x2b0)[0x5643578e5110]
wp_test_db        | mysqld(_Z13buf_read_pageRK9page_id_tRK11page_size_t+0xce)[0x56435789a33e]
wp_test_db        | mysqld(_Z16buf_page_get_genRK9page_id_tRK11page_size_tmP11buf_block_tmPKcmP5mtr_tb+0x4aa)[0x56435786957a]
wp_test_db        | mysqld(_Z31trx_rseg_get_n_undo_tablespacesPm+0x143)[0x56435780d1f3]
wp_test_db        | mysqld(+0x698c99)[0x564356dbdc99]
wp_test_db        | mysqld(_Z34innobase_start_or_create_for_mysqlv+0x2f3d)[0x5643577da06d]
wp_test_db        | mysqld(+0xf80438)[0x5643576a5438]
wp_test_db        | mysqld(_Z24ha_initialize_handlertonP13st_plugin_int+0x4f)[0x564356e390ff]
wp_test_db        | mysqld(+0xb8c0f6)[0x5643572b10f6]
wp_test_db        | mysqld(_Z40plugin_register_builtin_and_init_core_sePiPPc+0x2f0)[0x5643572b4300]
wp_test_db        | mysqld(+0x6bbece)[0x564356de0ece]
wp_test_db        | mysqld(_Z11mysqld_mainiPPc+0xc71)[0x564356de2a71]
wp_test_db        | /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf1)[0x7f7ce46452e1]
wp_test_db        | mysqld(_start+0x2a)[0x564356dd8eaa]
wp_test_db        | The manual page at http://dev.mysql.com/doc/mysql/en/crashing.html contains
wp_test_db        | information that should help you find out what is causing the crash.

你的 yaml 文件對我來說很好用。 我注意到的唯一一件事是 wordpress.environment ( WORDPRESS_DB_NAME=wordpress ) 中缺少數據庫名稱變量,但如果找不到,則默認為wordpress 我要指出這一點,以防您的實際副本具有 wordpress 以外的數據庫名稱。

這是適合我的撰寫文件:

version: "3"

services:
   db_node_domain:
     image: mysql:5.7
     volumes:
        - db_data:/var/lib/mysql
     restart: always
     environment:
        MYSQL_ROOT_PASSWORD: somewordpress
        MYSQL_DATABASE: wordpress
        MYSQL_USER: wordpress
        MYSQL_PASSWORD: wordpress
     container_name: wp_test_db

   wordpress:
     depends_on:
        - db_node_domain
     image: wordpress:latest
     ports:
        - '8000:80'
     expose:
        - 80
     restart: always
     environment:
        VIRTUAL_HOST: blog.example.com
        LETSENCRYPT_HOST: blog.example.com
        LETSENCRYPT_EMAIL: foo@example.com
        WORDPRESS_DB_HOST: db_node_domain:3306
        WORDPRESS_DB_USER: wordpress
        WORDPRESS_DB_PASSWORD: wordpress
        WORDPRESS_DB_NAME: wordpress # THIS WAS MISSING?
     container_name: wp_test
volumes:
  db_data:

networks:
  default:
    external:
      name: nginx-proxy

如果您想重新開始並重試,您可以運行docker-compose down然后docker-compose up 會破壞東西,所以要小心:)

您收到錯誤是因為 WordPress 容器在 MySQL 數據庫准備好並創建用戶之前嘗試連接它。 如果您在啟動服務后給它一些時間,將創建用戶並且 WordPress 將能夠訪問數據庫。 這個撰寫文件對我有用

version: "3"

services:
   db_node_domain:
     image: mysql:5.7
     volumes:
        - db_data:/var/lib/mysql
     restart: always
     environment:
        MYSQL_ROOT_PASSWORD: somewordpress
        MYSQL_DATABASE: wordpress
        MYSQL_USER: wordpress
        MYSQL_PASSWORD: wordpress
     container_name: wp_test_db

   wordpress:
     depends_on:
        - db_node_domain
     image: wordpress:latest
     expose:
        - 80
     ports:
        - 8090:80
     restart: always
     environment:
        VIRTUAL_HOST: blog.example.com
        LETSENCRYPT_HOST: blog.example.com
        LETSENCRYPT_EMAIL: foo@example.com
        WORDPRESS_DB_HOST: db_node_domain:3306
        WORDPRESS_DB_USER: wordpress
        WORDPRESS_DB_PASSWORD: wordpress
     container_name: wp_test
volumes:
  db_data:

networks:
  default:
    external:
      name: nginx-proxy

如果您想避免這些錯誤,則需要按照此處https://docs.docker.com/compose/startup-order/的描述實現wait for功能。

對於您收到的新錯誤,請嘗試刪除使用的卷

docker volume ls
docker volume rm db_data

執行“docker volume wordpress_db_data”可能會有所幫助。

我在使用 docker-compose 創建 WordPress 時遇到了同樣的問題。 這里有一些提示給你:

  1. 你有沒有啟動過這個 compose 項目的服務? 尤其是mysql服務。
  2. 如果是這樣,嘗試刪除 mysql 的持久卷可能會有所幫助。

這將有助於重新創建 mysql 服務。

所以,只需運行:

docker volume wordpress_db_data

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM