分类目录归档:MySQL

Mariadb 修改数据目录,并且打开了SELinux,SELinux配置命令

Job for mariadb.service failed because the control process exited with error code. See “systemctl status mariadb.service” and “journalctl -xe” for details.


MySQL 8.0启动报错,也是这个问题(已经chown了)

mysqld: File ‘./binlog.index’ not found (OS errno 13 – Permission denied)

chcon -R -t mysqld_db_t /mnt/mysql

参考页面:https://www.thegeekstuff.com/2016/05/move-mysql-directory/

MySQL GET_LOCK函数实现MySQL加锁

GET_LOCK(str,timeout)

Tries to obtain a lock with a name given by the string str, using a timeout of timeout seconds. A negative timeout value means infinite timeout. The lock is exclusive. While held by one session, other sessions cannot obtain a lock of the same name.

  • 尝试使用超时秒数的超时获得一个由字符串str给出的名称的锁。
  • 负超时值意味着无限超时。
  • 锁是独占的。
  • 只能由一个会话持有,其他会话无法获得同名的锁。

参考:https://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_get-lock
参考:https://blog.csdn.net/tangtong1/article/details/51792617

MySQL二进制日志清理

  1. 查看过期天数

show variables like ‘%logs%’;

2. 设置过期天数(最大值为99)

set global expire_logs_days = 99;

MySQL8.0 支持binlog_expire_logs_seconds参数,顾名思义就是日志过期秒数。

自动二进制日志文件删除的天数。 默认值为0,表示“不自动删除”。 可能的删除发生在启动时和二进制日志刷新。

2.1 生效问题

flush logs;

如果你发现设置没有生效,可能需要执行此命令。

3. 查看现有的日志文件

SHOW BINARY LOGS;

4. 手动清理较旧日志

PURGE BINARY LOGS TO ‘mysql-bin.000007’;

将mysql-bin.000007以前的日志清理掉,又或者

PURGE BINARY LOGS BEFORE ‘2018-01-06 12:12:12’;

将2018-01-06 12:12:12以前的日志清理掉

5. 修改MySQL配置文件

expire_logs_days = 99

 

create table和主从复制一坑

正确:
CREATE TABLE `chapter_lock_reason` (
`id` INT(11) NOT NULL AUTO_INCREMENT
PRIMARY KEY (`id`)
);

错误的方式:
CREATE TABLE xxx.`chapter_lock_reason` (
`id` INT(11) NOT NULL AUTO_INCREMENT
PRIMARY KEY (`id`)
);

MySQL ARCHIVE 引擎,从库突然Can’t write; duplicate key in table ‘nopay_record” on query.

这是ARCHIVE引擎的BUG

Error ‘Can’t write; duplicate key in table ‘nopay_record” on query. Default database: ‘doufu’. Query: ‘insert into `nopay_record` (`user_id`, `novel_id`, `chapter_id`, `channel`, `created_at`) values (3927416, 365027, 2499984, NULL, ‘2017-12-29 23:38:01′)’

表结构:

CREATE TABLE `nopay_record` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) NOT NULL,
`novel_id` int(11) NOT NULL,
`chapter_id` int(11) NOT NULL,
`channel` tinyint(4) DEFAULT NULL,
`created_at` timestamp NOT NULL DEFAULT ‘0000-00-00 00:00:00’,
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=ARCHIVE AUTO_INCREMENT=440357 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;

改成innodb

又一个MySQL坑

SELECT * FROM novel where title='一间客栈(连载)' ;
SELECT * FROM novel where title='一间客栈(连载) ' ;

SELECT * FROM novel where title=binary(‘一间客栈(连载)’ );
不加binary,MySQL会忽略大小写和首尾空格;

xtrabackup 快速增量备份教程

xtrabackup –backup –compress –target-dir=/mysqlbackup/full –user=aaa –host=hostname –password=xxxx –databases=ggggg

xtrabackup –backup –compress –target-dir=/mysqlbackup/incr –incremental-basedir=/mysqlbackup/full –user=aaa –host=hostname –password=xxxx –databases=ggggg

 

–compress 压缩