欢迎来到【一个大西瓜】的博客

不曾为梦想奋斗,拿什么去燃烧青春。有梦之人亦终将老去,但少年心气如昨。
太阳每一个时刻都同时是夕阳和朝阳,每天她沉入西边,意味着她同时从另一面土地升起。
扩大
缩小

【ASP.NET Core分布式项目实战】(四)使用mysql/mysql-server安装mysql

Docker安装Mysql

  1. 拉取镜像

    docker pull mysql/mysql-server
  2. 运行mysql

    docker run -d -p 3306:3306 --name mysql01 mysql/mysql-server
  3. 查看密码

    docker logs mysql01
  4. 进入容器

    docker exec -it mysql01 bash
  5. 进入mysql的命令行

    mysql -uroot -p
  6. 修改root密码
    use mysql;
    ALTER USER 'root'@'localhost' IDENTIFIED BY 'pwd123456';

创建新用户

CREATE USER 'test'@'localhost' IDENTIFIED BY 'pwd123456';
GRANT ALL PRIVILEGES ON *.* TO 'test'@'localhost' WITH GRANT OPTION;
CREATE USER 'test'@'%' IDENTIFIED BY 'pwd123456';
GRANT ALL PRIVILEGES ON *.* TO 'test'@'%' WITH GRANT OPTION;
# navicat连接mysql报错1251解决方案
# 更改加密方式
ALTER USER 'root'@'localhost' IDENTIFIED BY 'pwd123456' PASSWORD EXPIRE NEVER;
ALTER USER 'root'@'%' IDENTIFIED BY 'pwd123456' PASSWORD EXPIRE NEVER;
# 重新修改密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'pwd123456';
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'pwd123456';
# 刷新
FLUSH PRIVILEGES;

修改MYSQL 默认字符集

  1. 查看字符集命令

    docker exec -it mysql01 bash
    mysql -uroot -ppwd123456
    use mysql;
    show variables like '%char%';
    +--------------------------+--------------------------------+
    | Variable_name            | Value                          |
    +--------------------------+--------------------------------+
    | character_set_client     | latin1                         |
    | character_set_connection | latin1                         |
    | character_set_database   | utf8mb4                        |
    | character_set_filesystem | binary                         |
    | character_set_results    | latin1                         |
    | character_set_server     | utf8mb4                        |
    | character_set_system     | utf8                           |
    | character_sets_dir       | /usr/share/mysql-8.0/charsets/ |
    +--------------------------+--------------------------------+

     

  2. 修改my.cnf

    [mysqld]
    character-set-server=utf8mb4
    [client]
    default-character-set=utf8mb4 
    [mysql]
    default-character-set=utf8mb4

docker容器参数启动Mysql

  1. 创建容器
    docker run -d -p 3306:3306 -e MYSQL_USER="jeese" -e MYSQL_PASSWORD="pwd123456" -e MYSQL_ROOT_PASSWORD="pwd123456" -e MYSQL_ROOT_HOST=% --restart=always --name mysql01 mysql/mysql-server --character-set-server=utf8 --collation-server=utf8_general_ci
  2. 修改navicat连接

    docker exec -it mysql01 bash
    mysql -uroot -ppwd123456 use mysql; # navicat连接mysql报错1251解决方案 ALTER USER
    'jeese'@'%' IDENTIFIED WITH mysql_native_password BY 'pwd123456'; ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'pwd123456'; # 刷新 FLUSH PRIVILEGES;

MySql挂载资料卷

  1. mysql挂载资料卷
    #注意:需要先创建/docker/mysql/config/my.cnf文件和/docker/mysql/data文件夹
    cd /
    mkdir docker
    cd docker
    mkdir mysql
    cd mysql
    mkdir config
    mkdir data
    vim config/my.cnf
    
    [mysqld]
    user=mysql
    character-set-server=utf8
    [client]
    default-character-set=utf8
    [mysql]
    default-character-set=utf8
    
    # mysql挂载资料卷
    docker run -d -p 3306:3306 -v /docker/mysql/config/my.cnf:/etc/my.cnf -v /docker/mysql/data:/var/lib/mysql -e MYSQL_USER="jeese" -e MYSQL_PASSWORD="pwd123456" -e MYSQL_ROOT_PASSWORD="pwd123456" -e MYSQL_ROOT_HOST=% --restart=always --name mysql01 mysql/mysql-server --character-set-server=utf8 --collation-server=utf8_general_ci

     

  2. 修改navicat连接

    docker exec -it mysql01 bash
    mysql -uroot -ppwd123456 use mysql; # navicat连接mysql报错1251解决方案 ALTER USER
    'jeese'@'%' IDENTIFIED WITH mysql_native_password BY 'pwd123456'; ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'pwd123456'; # 刷新 FLUSH PRIVILEGES;

mongo挂载资料卷

cd /docker/
mkdir mongo
cd mongo
mkdir config
mkdir db

docker run -d -p 27017:27017 --name mongo01 -v /docker/mongo/config:/data/configdb -v /docker/mongo/db:/data/db --restart=always mongo

 

posted on 2019-07-01 15:44  一个大西瓜咚咚咚  阅读(1207)  评论(0编辑  收藏  举报

导航