docker 安装mysql8.0

1、window 安装docker desktop

查询镜像:docker images

删除镜像:docker rmi [镜像id]

查询容器:docker ps -a

删除容器:docker rm [容器id]

停止容器:docker stop [容器id]

重启容器:docker restart [容器id]

启动命令:docker run -it -v D:/docker/mysql/data:/var/lib/mysql -v D:/docker/mysql/conf/my.cnf:/etc/mysql/my.cnf --restart=always --name mysql8.0 -e MYSQL_ROOT_PASSWORD=root -p 3306:3306 -d mysql:8.0 --lower-case-table-names=1

-v: 挂载目录

my.cnf配置信息

[mysql]
#设置mysql客户端默认字符集
default-character-set=UTF8MB4
[mysqld]
#设置3306端口
port=3306
#允许最大连接数
max_connections=200
#允许连接失败的次数
max_connect_errors=10
#服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=UTF8MB4
#默认使用“mysql_native_password”插件认证
default_authentication_plugin=mysql_native_password
#开启查询缓存
explicit_defaults_for_timestamp=true
#创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
#等待超时时间秒
wait_timeout=60
#交互式连接超时时间秒
interactive-timeout=600
# 对数据库表大小写不敏感设置,默认设置为小写,比较也全部设置为小写在比较
lower-case-table-names=1
# 设置默认时区
default-time_zone='+8:00'

进入容器:docker exec -it mysql8.0 bash

执行mysql客户端

mysql -h 127.0.0.1 -P 3306 -u root -p
mysql -uroot -proot //-u用户 -p密码 登录

查询权限

use mysql;
select host,user,plugin,authentication_string from mysql.user;

更改本地主机密码,采用 mysql_native_password 本地客户端模式
alter user 'root'@'localhost' identified by 'root' password expire never;
alter user 'root'@'%' identified with mysql_native_password BY 'root';

//刷新设置
FLUSH PRIVILEGES;

springboot驱动链接

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <scope>runtime</scope>
</dependency>

<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus-boot-starter</artifactId>
    <version>${mybatis-plus.version}</version>
</dependency>

<mybatis-plus.version>3.2.0</mybatis-plus.version>

application.yml配置

spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/xxx?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT&allowPublicKeyRetrieval=true
    username: root
    password: root
posted @   糯米๓  阅读(413)  评论(0编辑  收藏  举报
努力加载评论中...
more_horiz
keyboard_arrow_up dark_mode palette
选择主题
点击右上角即可分享
微信分享提示