mysql

docker安装mysql8

拉取镜像:

    docker pull mysql:8.0.28

运行容器:

    sudo docker run -itd --name mysql8 -p3307:3306 -e MYSQL_ROOT_PASSWORD=admin123 [镜像id] --lower_case_table_names=1
要挂载目录参数:
    sudo docker run -itd --name mysql8 -p3307:3306 \
    -e MYSQL_ROOT_PASSWORD=denglibin \
    -v /mnt/e/sublinux/mysql-data/data:/var/lib/mysql \
    -v /mnt/e/sublinux/mysql-data/log:/var/log \
    -v /mnt/e/sublinux/mysql-data/mysql-files:/var/lib/mysql-files \
    [镜像id] --lower_case_table_names=1

进入容器:

    docker exec -it mysql8 /bin/bash

添加用户:

    create user 'zhangsan'@'%' identified with mysql_native_password by 'zhangsan';
    alter  user 'zhangsan'@'%' identified with mysql_native_password by 'zhangsan';

远程访问:

    grant all privileges on *.* to 'zhangsan'@'%'  with grant option;

刷新权限:

    flush privileges;
``
修改时区
vim /etc/mysql/my.cnf (没有vi 将文件拷贝出来修改后再拷贝回去)
在[mysqld]下加入
default-time_zone='+8:00'
中文乱码:

将如下配置写入\:mysqld.cnf中,拷贝到容器中的 /etc/mysql/conf.d/目录下  重启容器
[mysql.server]
default-character-set = utf8
[mysqld_safe]
default-character-set = utf8
[client]
default-character-set = utf8
退出容器,重启

关于作者

程序员,软件工程师,java, golang, rust, c, python,vue, Springboot, mybatis, mysql,elasticsearch, docker, maven, gcc, linux, ubuntu, centos, axum,llm, paddlepaddle, onlyoffice,minio,银河麒麟,中科方德,rpm