docker-compose环境下搭建mysql8
Docker安装Mysql8数据持久化到宿主主机----亲测
version: "3"
services:
mysql:
container_name: mysql
image: mysql:8.0.31
restart: always
volumes:
# 挂载mysql文件
- home/mysql_data:/var/lib/mysql
# 挂载mysql配置
- home/mysql_cnf:/etc/mysql
# 挂载mysql错误日志
- ./mysql_error_log:/var/log
ports:
- "8806:3306"
environment:
TZ: Asia/Shanghai
MYSQL_ROOT_PASSWORD: 123456
command:
--character-set-server=utf8mb4
--collation-server=utf8mb4_unicode_ci
--max_connections=2000
--wait_timeout=20000
进入mysql容器
1:docker exec -it mysql /bin/bash
2.执行命令输入密码:123456
mysql -u root -p
3.修改访问主机以及密码
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'admin666';
4.刷新一下权限
FLUSH PRIVILEGES;
就这么简单。。。可以连接上数据库了
mysql8.0设置binlog保存时间,并清除过期日志释放空间
一. 在线修改,即时生效
mysql> show variables like '%expire%';
+--------------------------------+---------+
| Variable_name | Value |
+--------------------------------+---------+
| binlog_expire_logs_auto_purge | ON |
| binlog_expire_logs_seconds | 2592000 |
| disconnect_on_expired_password | ON |
| expire_logs_days | 0 |
+--------------------------------+---------+
4 rows in set (0.02 sec)
mysql> set global expire_logs_days=1;
ERROR 3683 (HY000): The option expire_logs_days and binlog_expire_logs_seconds cannot be used together.
Please use binlog_expire_logs_seconds to set the expire time (expire_logs_days is deprecated)
mysql> set global binlog_expire_logs_seconds=86400;
Query OK, 0 rows affected (0.00 sec)
mysql> show variables like '%expire%';
+--------------------------------+-------+
| Variable_name | Value |
+--------------------------------+-------+
| binlog_expire_logs_auto_purge | ON |
| binlog_expire_logs_seconds | 86400 |
| disconnect_on_expired_password | ON |
| expire_logs_days | 0 |
+--------------------------------+-------+
4 rows in set (0.02 sec)
mysql> flush logs;
Query OK, 0 rows affected (2.77 sec)
mysql> show binary logs;
+---------------+------------+-----------+
| Log_name | File_size | Encrypted |
+---------------+------------+-----------+
| binlog.000034 | 1150850956 | No |
| binlog.000035 | 1073745962 | No |
| binlog.000036 | 1073765209 | No |
| binlog.000037 | 1036964608 | No |
| binlog.000038 | 1105127830 | No |
| binlog.000039 | 1136391108 | No |
| binlog.000040 | 1112828317 | No |
| binlog.000041 | 1109221590 | No |
| binlog.000042 | 165709537 | No |
| binlog.000043 | 955575 | No |
+---------------+------------+-----------+
10 rows in set (0.00 sec)
mysql> \q
查看binlog具体设置
查看binlog设置
mysql> show variables like '%expire%';
注意:mysql8.0以下版本binlog保存时效 以天为单位,参数为expire_logs_days,默认0为永不过期。mysql8.0以上版本binlog保存时效 以秒为单位,参数为binlog_expire_logs_seconds,默认的binlog过期时间为2592000秒,也就是30天。
示例设置过期日期为1天(1d=86400s):
mysql> set global binlog_expire_logs_seconds=86400;
清除日志
1.手动刷新清理过期日志
mysql> flush logs;
2.清除某个日志:
mysql> purge binary logs to 'binlog.000011';
3.清除某日前的日志:
mysql> purge binary logs before '2020-12-20';
注意:不要轻易手动去删除binlog,会导致binlog.index和真实存在的binlog不匹配,而导致expire_logs_day失效。
二.修改配置,重启生效
在配置文件 my.cnf 中修改参数如下:
[mysqld]
expire_logs_days=1 #日志过期时间为1天,若expire_logs_days=0,则为永不过期哦
max_binlog_size=500M #日志最多存放500M,超过500M后会被清除
mysql服务重启后配置生效
MYSQL8 如何设置不区分大小写
在 [mysqld] 部分中添加以下配置项:
lower_case_table_names=1
保存配置文件并重启MySQL服务,以使配置生效。你可以使用以下命令来重启MySQL服务:
sudo service mysql restart
使用以下 SQL 语句来验证是否成功设置了不区分大小写:
SHOW VARIABLES LIKE 'lower_case_table_names';
如果返回的值是 1,则说明设置成功。
查询或设置字符集
SHOW VARIABLES LIKE 'collation%';
SET collation_connection = 'utf8mb4_general_ci';
SET collation_server = 'utf8mb4_general_ci';
更多推荐
所有评论(0)