Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make a single table in mysql read-only

Tags:

mysql

How can I make a single table in mysql read only for a user while he still has write access to other tables in the same db?

Additional info

  • I have root access to the server
  • Tables are MyISAM
  • Server version is 5.0.51a-24+lenny2

thanks!

like image 868
ChrisR Avatar asked Oct 05 '10 07:10

ChrisR


People also ask

How do I make MySQL read only?

MySQL doesn't support WITH READ ONLY for CREATE VIEW . The line DEFINER = CURRENT_USER is not needed if you use the limited user to create the view. Or you can use an admin user to create the view and in this case the line DEFINER = must contain the name of the user that will own the view.

How do I give access to a specific table in MySQL?

Select the statements for only the tables you would like to grant access to and run those queries. For example, if we only wanted to grant access to the Users and Visitors table we would run: GRANT SELECT, SHOW VIEW ON mydatabase. `Users` to 'myuser'@`myhost`; GRANT SELECT, SHOW VIEW ON mydatabase.

Why is my table read only MySQL?

You should at least have the necessary privileges on your specific table. If that's the case, try to repair the table (it may have crashed). If you're still getting “read only” messages, check the file permissions in /var/lib/mysql/dbname/tbl_name (assuming your database is in /var/lib/mysql).

How do I turn off read only in MySQL?

To turn it off, you can use the SET GLOBAL statement as shown below: SET GLOBAL read_only=0; The option should now be turned off.


2 Answers

Revoke all previous privileges and then grant the specific new privileges:

REVOKE ALL ON db.table FROM user;
REVOKE ALL ON db.othertable FROM user;
GRANT SELECT ON db.table TO user;
GRANT SELECT, INSERT, UPDATE, DELETE ON db.othertable TO user;
like image 140
Emil Vikström Avatar answered Sep 27 '22 17:09

Emil Vikström


You can make a single MyISAM table read only by compressing the table. Use myisampack on the command line to pack the table.

More info can be found in the MySQL Manual: http://dev.mysql.com/doc/refman/5.0/en/myisampack.html

like image 36
ToBe_HH Avatar answered Sep 27 '22 15:09

ToBe_HH