Dokcer download and container change mysql password

Dokcer download and container change mysql password

insert image description here

The docker container downloads the mysql service (mysql:5.7)

  1. docker pulls mysql:5.7 image

    docker pull mysql:5.7

  2. Check if the image is pulled successfully

    docker images //View all images

    docker image ls

  3. start mysql:5.7

    docker run -d --name mysql -v ~/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=diqiu -p 3306:3306 mysql:5.7
    

    Note: diqiu is the password

  4. Enter the mysql container

    docker exec -ti mysql bash

  5. open remote link

    //login to mysql

    mysql -uroot -pdiqiu

    //Open remote connection

    GRANT ALL PRIVILEGES ON . TO ‘root’@’%’ IDENTIFIED BY ‘diqiu’ WITH GRANT OPTION;
    FLUSH PRIVILEGES;
    EXIT;

  6. Restart the mysql service

    docker restart mysql

change mysql password

  1. Query docker container service

    docker ps

  2. Enter the mysql service

    docker exec -ti mysql bash

  3. log in to mysql

    mysql -uroot -pdiqiu

  4. change mysql password

    set password for 'root' = password('new password');

  5. Modify the local mysql password (otherwise the client tool cannot be used to connect)

    set password for 'root'@'localhost'=password('new password');

Modify public network access

img

Guess you like

Origin blog.csdn.net/weixin_44975322/article/details/122063623