[Mysqld] port = 3306 #basedir = /var/lib/mysql datadir = /var/lib/mysql pid-file = /var/run/m
[Mysqld]
port = 3306
#basedir = /var/lib/mysql
datadir = /var/lib/mysql
pid-file = /var/run/mysqld/mysqld.pid
Socket = /var/run/mysqld/mysqld.sock
#secure-file-priv= NULL
secure-file-priv= /var/lib/mysql-files
lower_case_table_names=1
character-set-server=utf8mb4collation-server=utf8mb4_unicode_ci
max_connections=1500
max_connect_errors=100
default-storage-engine=INNODB
default_authentication_plugin=mysql_native_passWord
wait_timeout = 1800
interactive_timeout = 1800
#lock_wait_timeout = 3600
#tmp_table_size = 64M
#max_heap_table_size = 64M
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
#log-error = /var/log/mysql/error.log
# By default we only accept connections from localhost
#bind-address = 127.0.0.1
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0[mysql]
default-character-set=utf8mb4[client]
port=3306
default-character-set=utf8mb4#!includedir /etc/mysql/conf.d/
Docker run
docker run --restart=unless-stopped -d --name mysql -p 3306:3306 -v /data/jettechproduct/jettopro/poc/tools/mysql8.0/conf/my.cnf:/etc/mysql/my.cnf -v /data/jettechproduct/jettopro/poc/tools/mysql8.0/data:/var/lib/mysql -v /data/jettechproduct/jettopro/poc/tools/mysql8.0/mysql-files:/var/lib/mysql-files -e MYSQL_ROOT_PASSWORD=123456aA harbor.jettech.com/jettechtools/mysql:8.0.28
讲解:
default_authentication_plugin 参数的设定:
原来Mysql在之前的版本的关于password的加密方法都是使用的 mysql_native_password,
不过到MySQL8.0的时候换成了caching_sha2_password,需要我们安装额外的插件,下面我们就来演示一下如何不用装插件的方法来规避这个错误。
运行环境:Centos7.4 +MySQL 8.0.11版本
mysql> show variables like 'default_authentication_plugin';+-------------------------------+-----------------------+| Variable_name | Value |+-------------------------------+-----------------------+| default_authentication_plugin | caching_sha2_password |+-------------------------------+-----------------------+1 row in set (0.01 sec)mysql> select host,user,plugin from mysql.user;+-----------+------------------+-----------------------+| host | user | plugin |+-----------+------------------+-----------------------+| % | root | caching_sha2_password || localhost | mysql.infoschema | mysql_native_password || localhost | mysql.session | mysql_native_password || localhost | mysql.sys | mysql_native_password || localhost | root | caching_sha2_password |+-----------+------------------+-----------------------+5 rows in set (0.00 sec)
运行环境:Centos7.4 +MySQL 5.7版本
mysql> show variables like 'default_authentication_plugin';+-------------------------------+-----------------------+| Variable_name | Value |+-------------------------------+-----------------------+| default_authentication_plugin | mysql_native_password |+-------------------------------+-----------------------+1 row in set (0.01 sec)mysql> select host,user,plugin from mysql.user;+-----------+-----------+-----------------------+| host | user | plugin |+-----------+-----------+-----------------------+| localhost | root | mysql_native_password || localhost | mysql.sys | mysql_native_password || % | root | mysql_native_password |---------------------
可以看到MySQL8.0.11版本默认的认证方式是caching_sha2_password,而在MySQL5.7版本则为mysql_native_password。若想在MySQL8.0版本中继续使用旧版本中的认证方式需要在my.cnf文件中配置并重启,因为此参数不可动态修改。
mysql> set global default_authentication_plugin='mysql_native_password';ERROR 1238 (HY000): Variable 'default_authentication_plugin' is a read only variable
vim my.cnf[mysqld]default_authentication_plugin=mysql_native_password
另一种解决方法:兼容新老版本的认证方式。
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root' PASSWORD EXPIRE NEVER; #修改加密规则
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root'; #更新一下用户的密码
FLUSH PRIVILEGES; #刷新权限
--创建新的用户:
create user root@'%' identified WITH mysql_native_password BY 'root';
grant all privileges on *.* to root@'%' with grant option;
flush privileges;
--在MySQL8.0创建用户并授权的语句则不被支持:
mysql> grant all privileges on *.* to root@'%' identified by 'root' with grant option;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL Server version for the right syntax to use near 'identified by 'root' with grant option' at line 1
secure-file-priv:
当我要在 mysql 里导出数据的时候发现报错,报错内容如下
原理解释
secure-file-priv
是 mysql 中的一个系统变量,用来控制导入导出数据的操作,比如 LOAD DATA
或 SELECT ... INTO OUTFILE
或 LOAD_FILE()
show global variables like 'secure_file%'
查看该变量的设定值,可能有以下 3 种取值 NULL
。禁止导入导出操作解决办法
环境:mysql 8.0.26(用 homebrew
安装),Macbook Pro 2020 Intel Edition
1⃣️ 创建对应文件,~/.my.cnf
,用自己习惯的文本编辑器即可,我用的 nano
,里面内容如下
[mysqld]secure_file_priv = ''show global variables like 'secure_file%';
var lib mysql-files_Docker启动MySQL 8.0 报错: docker Supplied value : /var/lib/mysql-files
这个问题是在启动容器尝试对容器挂载数据卷的时候出现的, 不挂载数据卷不会有这个问题。
我的数据卷挂载参数如下, 其中报错就是因为缺少第二行, 对my.cnf文件也挂载也就是对在my.cnf中的secure_file_priv=/var/lib/mysql-files 目录页进行挂在就额可以了或者在容器中创建此目录或者和datadir公用目录【secure_file_priv=/var/lib/mysql】
[mysqld]# 设置3306端口port=3306# 设置mysql的安装目录basedir=/usr/local/mysql# 设置mysql数据库的数据的存放目录datadir=/usr/local/mysql/mysqldb# 允许最大连接数max_connections=1000# 允许连接失败的次数。这是为了防止有人从该主机试图攻击数据库系统max_connect_errors=100# 服务端使用的字符集默认为UTF8character-set-server=utf8mb4# 创建新表时将使用的默认存储引擎default-storage-engine=INNODB# 默认使用“mysql_native_password”插件认证default_authentication_plugin=mysql_native_password#是否对sql语句大小写敏感,1表示不敏感lower_case_table_names = 1#MySQL连接闲置超过一定时间后(单位:秒)将会被强行关闭#MySQL默认的wait_timeout 值为8个小时, interactive_timeout参数需要同时配置才能生效interactive_timeout = 1800wait_timeout = 1800#Metadata Lock最大时长(秒), 一般用于控制 alter操作的最大时长sine mysql5.6#执行 DML操作时除了增加innodb事务锁外还增加Metadata Lock,其他alter(DDL)session将阻塞lock_wait_timeout = 3600#内部内存临时表的最大值。#比如大数据量的group by ,order by时可能用到临时表,#超过了这个值将写入磁盘,系统IO压力增大tmp_table_size = 64Mmax_heap_table_size = 64M[mysql]# 设置mysql客户端默认字符集default-character-set=utf8mb4[client]# 设置mysql客户端连接服务端时默认使用的端口port=3306default-character-set=utf8mb4
来源地址:https://blog.csdn.net/Michaelwubo/article/details/128845984
--结束END--
本文标题: docker mysql8 my.cnf 配置讲解
本文链接: https://lsjlt.com/news/388755.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-10-23
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0