Reputation: 15279
When I want to execute an update
query on my table I got an error saying:
1036 - Table
data
is read only.
How can I fix that?
Table attributes in /var/db/mysql
are set to 777
.
'Repair Table' function doesnt seems to help.
Is there anything I can do with that?
Upvotes: 33
Views: 136992
Reputation: 4331
Over Debian Linux I added the bellow line inside /etc/mysql/my.cnf
[mysql]
innodb_force_recovery = 0
Now, restart it
service mysql restart
Upvotes: 0
Reputation: 515
In case you (like me) are trying to temporarily alter data via the MySQL Workbench interface:
If the table does not have a primary key, MySQL Workbench has no way of identifying the row you are trying to alter, so therefore you cannot alter it.
Solution in that case is to either alter the data via another route, or simply to add a primary key to the table.
Upvotes: 12
Reputation: 1485
In my case, mysql config file had innodb_force_recovery = 1. Commenting that out solved the issue.
Upvotes: 43
Reputation: 111
In my case there was a table with read-only state set and when I tried to restart mysql service it would not even start again and with no descriptive error.
Solution was to run fsck
on the drive (with many fixes), which was advised after Ubuntu reboot.
I'm running Ubuntu in VirtualBox under Windows and it often hangs or is having functionality problems.
Upvotes: 0
Reputation: 51
If you are running selinux in enforcing mode then check your /var/log/messages for audit faults. If you see the tell-tale "****" messages about selinux blocking write access to your table files in / then you need to relabel those files so that they have this label:
system_u:object_r:mysqld_db_t:s0
What you could have is a broken label from copying those files over from a user directory (such as during a recovery attempt).
There's a great resource for selinux here:
Just remember that you will need to do this for all of those files, which could be many. Then you will want to run the "restorecon -R -v " command to get the recursive (-R) application of the new labels. There is no support for -R in the semanage command, as far as I could tell.
For reference, the semanage command to relabel looks like this:
semanage fcontext -a -t mysqld_db_t 'filename'
The quoting of the file name is critical for the command to work.
Upvotes: 0
Reputation: 1
maybe you get read only error from your table storage engine.
Check you Storage Engine, maybe if it is MRG_MYISAM change it to MyISAM and try again.
Upvotes: 0
Reputation: 294
I solved the same issue by editing app. armour configuration file. Found the answer here: https://stackoverflow.com/a/14563327/31755661
Upvotes: 0
Reputation: 338
On windows I use Xampp server I comment the line in my.ini
innodb_force_recovery = 1
to #innodb_force_recovery = 1
the problem resolved
Upvotes: 0
Reputation: 309
My situation is everytime I needed to edit "innodb_force_recovery = 1" in my.ini to force mysql to start, and the error log showed some error said:
Attempted to open a previously opened tablespace. Previous tablespace mysql/innodb_table_stats uses space ID: 1 at filepath: .\mysql\innodb_table_stats.ibd. Cannot open tablespace profile/profile_commentmeta which uses space ID: 1 at filepath: .\profile\profile_commentmeta.ibd
I didn't know why this file was not able to open and it caused so many other"table read only" problems to other databases too.
So here is how I fixed this problem in a simple way without hurting other files.
1 First of all, make sure if you add innodb_force_recovery = 1 below [mysqld] in my.ini file, and it is working, under path: X:\xampp\mysql\bin\my.ini
2 Then next step, export all the databases through localhost/phpmyadmin under the export tab, and store them somewhere, like this:
3 comment out the data filefolder to data-bak, then create a new data filefolder,
4 Next step, import all .sql database back from phpmyadmin panel, please also copy phpmyadmin filefolder from the old data-bak filefolder to the new data filefolder. If any file is necessary, go back to data-bak filefolder to copy and paste.
Now all fixed and done, don't need to force mysql to start everytime. Hope this also works for you.
Upvotes: 3
Reputation: 327
You should change owner to MYSQL:MYSQL.
Use this command: chown -Rf mysql:mysql /var/lib/mysql/DBNAME
Upvotes: 7
Reputation: 493
One other way to receive this error is to create your table with a "Like" statement and use as source a merged table. That way the newly create table is read-only and can't "receive" any new records.
so
CREATE TABLE ic.icdrs_kw37 LIKE ic.icdrs ... #<- a merged table.
then:
REPLACE INTO ic.icdrs_kw37 ... # -> "Table is read-only"
bug or feature?
Upvotes: -1
Reputation: 9200
who owns /var/db/mysql and what group are they in, should be mysql:mysql. you'll also need to restart mysql for changes to take affect
also check that the currently logged in user had GRANT access to update
Upvotes: 34
Reputation: 126752
MySQL doesn't have write access to the database file. Check the permissions and the owner of the file.
Upvotes: 2