编程笔记

lifelong learning & practice makes perfect

docker-mysql

https://hub.docker.com/_/mysql?tab=description&page=1&ordering=last_updated

  1. 拉取镜像
    docker pull mysql

  2. 运行

    1
    docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag

    where some-mysql is the name you want to assign to your container, my-secret-pw is the password to be set for the MySQL
    root user and tag is the tag specifying the MySQL version you want. See the list above for relevant tags.

    1
    docker run --name docker_mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=your_password -d mysql
  3. 修改验证密码,修改后才能用root@密码登陆

    1
    ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'your_password';
  4. 创建新用户

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    mysql8版本执行 grant all privileges on *.*  to  'root'@'%'  identified by 'root'  with grant option;
    会报语法错误 ERROR 1064 (42000)

    应先创建新用户
    create user 'admin'@'%' identified by 'password';

    执行授权

    GRANT ALL PRIVILEGES ON *.* TO 'admin'@'%';
    (MariaDB: GRANT ALL PRIVILEGES ON *.* TO 'admin'@'%' identified by 'password';)

    刷新
    flush privileges;

    授权远程

    ALTER USER 'admin'@'%' IDENTIFIED WITH mysql_native_password BY 'password';
    (MariaDB: ALTER USER admin@'%' IDENTIFIED VIA mysql_native_password;)

    刷新
    flush privileges;

    references: https://blog.csdn.net/java_cai_niao_han/article/details/110442608

欢迎关注我的其它发布渠道