The MySQL server is running with the --read-only option so it cannot execute this statement

来自:网络
时间:2020-10-28
阅读:

正在开会,同事电话反映开发库不能写入了,错误信息如下:

1209 - The MySQL server is running with the--read-only option so it cannot execute this statement

一般这个错误有两种原因:

1.连到从库了。从库一般设置为只读。

2.主库的read_only参数被修改为1

开发人员是普通用户应该没有权限修改这个参数的值。

DBA也不会去主动修改这个参数。那究竟是什么原因导致开发库不能写入了呢?

首先确认了不是开发人员的问题,因为部门的200多位研发都遇到了这个问题。

为了先解决问题,先去查询主库上read_only参数的值。果然read_only被设置为1.

手工修改为0后,问题解决。问题是read_only为什么会设置为1呢?

解决步骤如下:

mysql> select @@read_only;

+-------------+

| @@read_only |

+-------------+

| 1 |

+-------------+

1 row in set (0.00 sec)

mysql> set global read_only=0;

Query OK, 0 rows affected (0.00 sec)

检查mysql的错误日志发现有如下信息:

151231 13:55:11 mysqld_safe Number ofprocesses running now: 0

151231 13:55:11 mysqld_safe mysqldrestarted

由此可知MySQL发生了重启。重启的原因是什么呢?

检查了系统日志,发现了如下错误:

#tail -100f /var/log/message

Dec 31 13:55:11 mysql2dev kernel: [8680] 500 8680 27084 92 3 0 0 bash

Dec 31 13:55:11 mysql2dev kernel: Out ofmemory: Kill process 12805 (mysqld) score 964 or sacrifice child

Dec 31 13:55:11 mysql2dev kernel: Killedprocess 12805, UID 500, (mysqld) total-vm:13146848kB, anon-rss:7870704kB,file-rss:16kB

Dec 31 13:55:11 mysql2dev kernel: rsyslogdinvoked oom-killer: gfp_mask=0x201da, order=0, oom_adj=0, oom_score_adj=0

Dec 31 13:55:11 mysql2dev kernel: rsyslogdcpuset=/ mems_allowed=0-1

Dec 31 13:55:11 mysql2dev kernel: Pid:21035, comm: rsyslogd Not tainted 2.6.32-358.el6.x86_64 #1

Dec 31 13:55:11 mysql2dev kernel: CallTrace:

由这条错误可知,是由于内存溢出导致了mysql的重启

Out of memory: Kill process 12805 (mysqld)score 964 or sacrifice child

那是什么导致了内存溢出呢?

查看了系统的历史命令后发现有同事在做备份,而此时的系统的压力又比较大,且次系统没有设置交换分区,以上原因导致了MySQL的重启。

Swap: 0 0 0

为什么重启会导致read_only=1呢? 可能是配置文件中设置了read_only ,检查配置文件

#grep read_only my.cnf

read_only = on

这时开发环境突然不能写入的原因终于水落石出了。

你可能会问,主库为什么设置read_only=on呢,因为原来是一个MMM环境。

现在已经把MMM环境摘掉,所以将配置文件中的read_only 设置为0,至此开发库不能写入问题宣告解决。

MySQL报错:The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement等问题

1.登录的mysql:mysql –u root –p

mysql> set global read_only=0;
(关掉新主库的只读属性)

flush privileges;

2.修改mysql配置文件my.cnf,该文件在/etc目录下

The MySQL server is running with the --read-only option so it cannot execute this statement

The MySQL server is running with the --read-only option so it cannot execute this statement

重启mysql服务:service mysqld restart

ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot exe

在安装Mysql8.0.3过程中重置密码时报了这个错误, 原因是没有设置密码时需要在/etc/my.cnf中添加这段时才能操作mysql

#跳过密码验证

skip-grant-tables

但是添加完这句后操作mysql又报了这个错误, 这就成了一个死循环, 最后发现了解决办法,

这是因为权限设置了但还没有刷新导致的。

先执行

flush privileges;

再执行sql语句, 成功了

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的密码';

返回顶部
顶部