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 ?
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.
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).
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.
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.
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
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 ;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With