MariaDB [(none)]> show global variables like "%read_only%"; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | read_only | OFF | +---------------+-------+ 1 row inset (0.00 sec)
MariaDB [(none)]> set global read_only=1; #1是只读,0是读写 Query OK, 0 rows affected (0.08 sec)
MariaDB [(none)]> show global variables like "%read_only%"; #再次查询读写状态 +---------------+-------+ | Variable_name | Value | +---------------+-------+ | read_only | ON | +---------------+-------+ 1 row inset (0.00 sec)
[mysqld] log-bin="/tmp"#设置开启日志,也可不指定日志保存位置 expire_logs_days = 10 #设置日志自动清理天数 max_binlog_size = 100M #定义了单个文件的大小限制
2.添加完毕后,重启数据库进程,即可打开二进制日志啦.
[root@localhost~]# systemctl restart mariadb [root@localhost~]# mysql Welcome to the MariaDB monitor. Commands endwith ; or \g. Your MariaDB connection id is2 Server version: 5.5.60-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;'or'\h'for help. Type '\c'to clear the current input statement.
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/; /*!40019 SET @@session.max_insert_delayed_threads=0*/; /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/; DELIMITER /*!*/; mysqlbinlog: File 'mariadb-bin.000001' not found (Errcode: 2) DELIMITER ; # End of log file ROLLBACK /* added by mysqlbinlog */; /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; /*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
删除二进制日志:
1.我们可以手动删除二进制日志,通过使用reset master语句删除所有日志,SQL语句如下:
[root@localhost ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 4 Server version: 5.5.60-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h'forhelp. Type '\c' to clear the current input statement.
[root@localhost ~]# systemctl restart mariadb [root@localhost ~]# mysql Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 2 Server version: 5.5.60-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h'forhelp. Type '\c' to clear the current input statement.
MariaDB [(none)]> show variables like 'log_error'; +---------------+------------------------------+ | Variable_name | Value | +---------------+------------------------------+ | log_error | /var/log/mariadb/mariadb.log | +---------------+------------------------------+ 1 row inset (0.01 sec)
[root@localhost ~]# cat /var/log/mariadb/mariadb.log |head -n 10 181224 20:28:49 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql 181224 20:28:49 [Note] /usr/libexec/mysqld (mysqld 5.5.60-MariaDB) starting as process 1622 ... 181224 20:28:49 InnoDB: The InnoDB memory heap is disabled 181224 20:28:49 InnoDB: Mutexes and rw_locks use GCC atomic builtins 181224 20:28:49 InnoDB: Compressed tables use zlib 1.2.7 181224 20:28:49 InnoDB: Using Linux native AIO 181224 20:28:50 InnoDB: Initializing buffer pool, size = 128.0M 181224 20:28:50 InnoDB: Completed initialization of buffer pool InnoDB: The first specified data file ./ibdata1 did not exist: InnoDB: a new database to be created!
删除错误日志:
[root@localhost~]# mysql Welcome to the MariaDB monitor. Commands endwith ; or \g. Your MariaDB connection id is3 Server version: 5.5.60-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;'or'\h'for help. Type '\c'to clear the current input statement.