简体   繁体   中英

Docker - Can't access MySQL CLI in container

In my MySQL container that I have configured per the official image , it does not allow me to access the CLI from my host machine, nor any other of my containers, despite being linked:

用户'root'@'172.17.0.3'的访问被拒绝

Now, I know that I have not configured external access on my MySQL container, but how can I configure it if I can't even access the CLI to grant myself permissions? Could I create a Dockerfile and change some system settings before the initial installation of MySQL? If so, how would I go about doing that?

My fig.yml file, which is used to set up my MySQL container:

mysql:
  image: mysql:latest
  volumes:
    - .:/mydir
  working_dir: /mydir
  ports:
    - "3306:3306"
  environment:
    - MYSQL_DATABASE=mydb
    - MYSQL_ROOT_PASSWORD=mypass

The answer is in your screenshot. (using password: NO). Add a -p to your mysql command line.

You can try to set the environment variable MYSQL_PWD with the password for root. It's the official environment variable for the client.

http://dev.mysql.com/doc/refman/5.6/en/password-security-user.html

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