MySQL ERROR 1036 occurs when the database cannot write to a table due to permission issues or read-only settings. This usually happens after copying database files, incorrect ownership, or enabling global read-only mode. Most commonly resolved by fixing file permissions.
MySQL ERROR 1036 (ER_OPEN_AS_READONLY) indicates that the database server detected a table is in read-only mode, preventing any INSERT, UPDATE, or DELETE operations. SELECT queries will still work, but any DML statement attempting to modify data will fail. This is a protection mechanism that MySQL uses to prevent accidental data corruption when tables cannot be safely written to.
First, verify the ownership of your MySQL data directory. SSH into your server and run:
ls -la /var/lib/mysql/The output should show that the mysql user owns the directory. If it shows a different user (like root or your username), this is the problem. Look for entries like:
drwx------ 5 mysql mysql 4096 Dec 22 10:15 .Note: If your MySQL data directory is in a different location (check with SHOW VARIABLES LIKE 'datadir'; in MySQL), adjust the path accordingly.
If the ownership is wrong, fix it by running:
sudo chown -R mysql:mysql /var/lib/mysqlThis recursively changes all files and directories under /var/lib/mysql to be owned by the mysql user. If your data directory is elsewhere, replace the path accordingly.
You can verify the change worked by running the ls command again.
Ensure the mysql user has proper read/write permissions. Run:
sudo chmod -R 755 /var/lib/mysqlFor more restrictive permissions (often better for security), use:
sudo chmod -R 700 /var/lib/mysqlFor specific database directories:
sudo chmod -R 660 /var/lib/mysql/database_name/*Verify with ls -la to confirm write permissions are present (look for rw in the permissions).
After fixing ownership and permissions, restart MySQL to ensure it detects the changes:
sudo systemctl restart mysqlOr for older systems:
sudo service mysql restartOn macOS with Homebrew:
brew services restart mysqlWait for the service to fully restart before attempting queries.
Connect to MySQL and check if global read_only mode is enabled:
SHOW GLOBAL VARIABLES LIKE 'read_only';If the result shows ON, the global read-only setting is enabled. Disable it with:
SET GLOBAL read_only = OFF;Note: Only users with SUPER privilege can modify this setting. Make sure this change is intentional, as it may have been set to protect your database.
Test that the error is resolved by attempting a simple write operation:
INSERT INTO your_table (column1) VALUES ('test_value');If successful, the issue is resolved. If the error persists, verify that:
1. You're connected as a user with write permissions
2. You're attempting to write to the correct table
3. The service restart completed successfully
Check MySQL error logs for more details:
tail -50 /var/log/mysql/error.logFor MyISAM tables specifically, if ownership and permissions are correct but the table still appears read-only, it may be corrupted. Repair it using: sudo myisamchk --recover /var/lib/mysql/database_name/table_name.MYI followed by a MySQL restart.
For InnoDB tables, check if a specific tablespace is set to read-only: SELECT * FROM INFORMATION_SCHEMA.INNODB_TABLESPACES WHERE SPACE_TYPE = 'General' AND READ_ONLY = 1;
In replication scenarios, if this is a replica server, verify that replica_read_only is not unintentionally set to ON. The error can also occur if you're using SELinux or AppArmor with overly restrictive policies—check security logs if standard permission fixes don't work.
When migrating databases between servers by copying files directly (rather than using mysqldump), always restore proper permissions. This is why mysqldump with pipe to the new server is the recommended approach for database migration.
EE_WRITE (3): Error writing file
How to fix "EE_WRITE (3): Error writing file" in MySQL
CR_PARAMS_NOT_BOUND (2031): No data supplied for parameters
How to fix "CR_PARAMS_NOT_BOUND (2031): No data supplied for parameters" in MySQL
CR_DNS_SRV_LOOKUP_FAILED (2070): DNS SRV lookup failed
How to fix "CR_DNS_SRV_LOOKUP_FAILED (2070): DNS SRV lookup failed" in MySQL
ERROR 1146: Table 'database.table' doesn't exist
How to fix "ERROR 1146: Table doesn't exist" in MySQL
ERROR 1040: Too many connections
How to fix "ERROR 1040: Too many connections" in MySQL