zoukankan      html  css  js  c++  java
  • Docker安装Mysql

    1、拉取mysql镜像

    docker pull mysql  //拉取最新版本的mysql

    2、启动mysql镜像

    docker run --name mysql  -p 3306:3306 -e MYSQL_ROOT_PASSWORD=xxxxx  -d mysql

    --name:镜像别名

    -p:映射端口

    -e:设置环境变量,也就是root的密码

    -d:后台启动

    第一个mysql表示自定义容器名称,第二个mysql表示镜像的名称。

    在这一步的时候,却报错了,通过 docker logs mysql看到下面日志,查了下是没有swap空间了。

    [ERROR] InnoDB: mmap(137428992 bytes) failed; errno 12
    [ERROR] InnoDB: Cannot allocate memory for the buffer pool
    [ERROR] InnoDB: Plugin initialization aborted with error Generic error
    [ERROR] Plugin 'InnoDB' init function returned error.
    [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
    [ERROR] Failed to initialize builtin plugins.
    [ERROR] Aborting

    通过命令 free -m 查看是否有swap空间。

    1. 创建swapfile文件
    2. 执行:sudo dd if=/dev/zero of=swapfile路径  bs=1M count=3k
    3. 将文件变成swap分区 sudo mkswap swapfile
    4. 设置swapfile分区有效:sudo swapon swapfile
    5. 设置重启后依然有效:修改/etc/fstab文件,添加 swapfile路径 swap swap defaults 0 0

    然后重新启动容器。

    3、设置远程

    docker exec -it mysql bash   //进入容器
    mysql -u root -p    //登录mysql  输入密码
    use mysql  
    grant all privileges on *.* to 'root'@'%';  //设置远程授权

    到这里就完了,但是新版本8以后的mysql改了默认的加密方式为 caching_sha2_password,导致登录报错。

    查询用户和对应的域,%代表所有域都可已登录,localhost代表只有本地能登录,plugin表示加密方式。

    4、修改加密方式

    alter user 'root'@'%' identified with mysql_native_password by '密码'; //修改为老版加密方式 mysql_native_password 
  • 相关阅读:
    Ubuntu18.04下使用pip3.8报错subprocess.CalledProcessError: Command ‘(‘lsb_release‘, ‘-a‘)‘ returned non-ze
    解决报错:ModuleNotFoundError: No module named ‘_sqlite3‘
    shell命令中find的用法
    Ubuntu 中卸载软件
    git使用
    django celery 使用
    Django 学习中遇到的问题
    1
    Mac 下安装brew(文末方法亲测有效)
    经典类与新式类的继承顺序
  • 原文地址:https://www.cnblogs.com/MicroHeart/p/13817743.html
Copyright © 2011-2022 走看看