MySQL set read-only mode

Source: Internet
Author: User

Common phenomena:

The MySQL master-slave server is often maintained in operations, but from the library we are only used for reading.

General access is only authorized to read account, but sometimes maintenance work may not be a person doing, you can not guarantee that all follow this standard operation.

A colleague may authorize the slave library MySQL account to be all or select,update,insert,delete. There is also a situation is the master and slave to do all the data synchronization, in the main library authorized account is also synchronized to the top of the library, of course, the master account will certainly have Select,update,insert,delete permissions.

Problems that exist:

Then the problem comes, when the operator or the developer program incorrectly connected to MySQL slave as the master, and so on, then sad to all the data modification to operate the slave.

To avoid this problem, we need to set MySQL's slave to read-only mode.

Workaround:

The demo is as follows:

MySQL>set global read_only=10 rows affected (0.00 Sec

Authorized normal MySQL test account

Mysql> Grant Select,Insert,Update,Delete  onS18.*  to 'Test'@'127.0.0.1'identified by '123456'; Query OK,0Rows affected,1Warning (0.00Sec

Use the test account login to delete and other operations, will prompt--read-only error

Mysql> Delete  fromStudentwhereSid= -; ERROR1290(HY000): the MySQL server isRunning withThe--read-only option so IT cannotExecuteThis statementmysql> InsertClassValues(5, third grade 10 classes); ERROR1290(HY000): the MySQL server isRunning withThe--read-only option so IT cannotExecuteThis statement

Note: Set global Read_only=1 does not take effect on accounts that have super privileges, so try to avoid adding super privileges when you authorize your account.

MySQL set read-only mode

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.