简体   繁体   中英

How do you access the wordpress mysql database when running it in docker?

Thanks in advance for helping me out with this. I've been turning myself in circles trying to figure this out, but chances are that I'm missing something really simple.

I followed the quickstart guide to using Wordpress in Docker here: https://docs.docker.com/compose/wordpress/

However, I am having trouble accessing my mysql database.

Here is my docker-compose file (pretty much just copied from the tutorial):


services:
   db:
     image: mysql:5.7
     volumes:
       - db_data:/var/lib/mysql
     restart: always
     command: "--default-authentication-plugin=mysql_native_password"
     environment:
       MYSQL_ROOT_PASSWORD: somewordpress
       MYSQL_DATABASE: wordpress
       MYSQL_USER: wordpress
       MYSQL_PASSWORD: wordpress
       MYSQL_ROOT_HOST: "%"

   wordpress:
     depends_on:
       - db
     image: wordpress:latest
     ports:
       - "8000:80"
     restart: always
     environment:
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: wordpress
       WORDPRESS_DB_PASSWORD: wordpress
       WORDPRESS_DB_NAME: wordpress
volumes:
    db_data: {}

I am able to get into a shell for my database container by running docker exec -it db_name /bin/bash .

Once there, I cannot run mysql. Here are my attempts to do so:

root@79f23dc84547:/# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

when I try with the username and password:

root@79f23dc84547:/# mysql -u wordpress -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'wordpress'@'localhost' (using password: YES)

the environmental variable was clearly set:

root@79f23dc84547:/# echo $MYSQL_ROOT_PASSWORD    
somewordpress

Again, thank you in advance!

Your client need to run with the same option as your server ( doc ). Actually for version 5.7 you should remove the option to fix your ( issue ).

#remove
command: "--default-authentication-plugin=mysql_native_password"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM