How to fix ERROR 1036: Table is read only in MySQL
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.
Quick fix
Fixes ERROR 1036: Table is read only
ls -la /var/lib/mysql/- Check current file ownership of MySQL data directory
- Fix file ownership if incorrect
- Fix file permissions if too restrictive
- Restart the MySQL service
ls -la /var/lib/mysql/ERROR 1036: Table is read only
What this error means
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.
Typical symptoms
- INSERT queries fail with "ERROR 1036: Table is read only"
- UPDATE and DELETE operations fail even though SELECT queries work fine
- Error occurs consistently across all write operations on affected tables
- Problem persists after restarting the application but not after restarting MySQL
- Issue appears after copying/restoring database files to a new server
- Permissions show as restrictive when checking filesystem with ls -la
Common causes
- Incorrect file ownership of database directory or table files (not owned by mysql:mysql user)
- Restrictive file permissions (chmod settings preventing mysql user from writing)
- Global read_only setting enabled on the MySQL server
- Filesystem mounted in read-only mode
- Database files copied from another server without preserving permissions
- InnoDB tablespace set to read-only mode
- MyISAM table corruption requiring recovery
- Replica misconfiguration causing replication-only mode
How to fix "ERROR 1036: Table is read only"
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.logAdvanced notes
For 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.
Frequently asked questions
- What does "ERROR 1036: Table is read only" mean?
- 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.
- How do I fix "ERROR 1036: Table is read only"?
- 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.
- What causes "ERROR 1036: Table is read only"?
- Incorrect file ownership of database directory or table files (not owned by mysql:mysql user) Restrictive file permissions (chmod settings preventing mysql user from writing) Global read_only setting enabled on the MySQL server
- Is the "ERROR 1036: Table is read only" error serious?
- Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.
Official resources & further reading
- 📚MySQL Official Documentation
- 📖MySQL Official Error Reference(Official Docs)
- 💬Percona Community Forum Discussion(Stack Overflow)