Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read only table in mysql

Tags:

database

mysql

I'm using mysql database. In that I have table called tbl_user I need to change this as read only table to every user. How to change the table as read only ?

like image 962
Dhileepan Avatar asked Sep 10 '12 10:09

Dhileepan


People also ask

How do I make MySQL read only?

Grant read-only permission to the MySQL user* TO $user@'127.0. 0.1′ IDENTIFIED BY '$password' REQUIRE SSL; FLUSH PRIVILEGES; This creates a new read-only MySQL local user that can access your databases.

Why is my table read only SQL?

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.

How do I make a table read only in MySQL workbench?

Create a Read-Only Table Using MySQL Workbench. Open MySQL Workbench and create a database named testing_workbench_readonly . If you already have a database with a read-only table, skip to the next section. Otherwise, create a table in the new database using the following SQL.


2 Answers

To grant all user select, use public instead of a complete user list

REVOKE ALL ON tbl_user FROM PUBLIC
GRANT SELECT ON tbl_user TO PUBLIC
like image 89
JaMaBing Avatar answered Sep 22 '22 11:09

JaMaBing


Besides revoking the permission, another way is to take use of trigger

/* triggers */
delimiter //

DROP TRIGGER IF EXISTS stop_table_insert;
CREATE TRIGGER stop_table_insert
  BEFORE INSERT ON `table`
FOR EACH ROW
BEGIN
   SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Database maintainance';
END;//

DROP TRIGGER IF EXISTS stop_table_update;
CREATE TRIGGER stop_table_update
  BEFORE UPDATE ON `table`
FOR EACH ROW
BEGIN 
   SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Database maintainance';
END;//

DROP TRIGGER IF EXISTS stop_table_delete;
CREATE TRIGGER stop_table_delete
  BEFORE DELETE ON `table`
FOR EACH ROW
BEGIN
   SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Database maintainance';
END;//


delimiter ;
like image 38
Mr.Wang from Next Door Avatar answered Sep 25 '22 11:09

Mr.Wang from Next Door