I am preparing a common schema
o database
that contains tables in common use across multiple projects. All MySQL users must have permission to run ONLY select
on those tables. For that I do:
drop database if exists common_schema;
CREATE DATABASE common_schema CHARACTER SET utf8 COLLATE utf8_general_ci;
grant select on common_schema.* to ""@"";
flush privileges;
use common_schema;
set foreign_key_checks = 0;
-- creación_de_tablas
-- inserts
-- foreign_keys
set foreign_key_checks = 1;
The entire operation is executed with a bash script that is as follows:
cat *.sql > sql_completo.sql1
mv sql_completo.sql1 sql_completo.sql
mysql -u root -p < sql_completo.sql
rm sql_completo.sql
This script concatenates all the SQL files and loads it into MySQL. The problem is that any user can insert, modify or delete records from common_schema
, which it shouldn't be.
I am using MySQL 5.6.51.
Thanks in advance!
Two things:
flush privileges
is unnecessary in recent versions of MySQL if you do things correctly. It is a legacy of versions 3.x when you had to refresh everything when modifying the metadata tables. Now, if you do a GRANT, the permissions take effect immediately (if you did an INSERT to the permissions tables, then you have to do the flush). So there is no bug in the command because you are not doing anything new by running it.REVOKE ALL ON common_schema FROM 'usuario_pepito'@'%';
to restrict a user. Then you give the SELECT with GRANT. No flush.I found a way to do it.
Although permissions must be explicitly defined,
grant select on common_schema.* to ''@'%';
it gave all permissions to all users.I remind you: the idea was a
schema
common one with permission ofselect
(only) all users, without sacrificing root/admin.First you have to revoke the permissions, and then assign the necessary ones:
In this way, all the permits that should not have been awarded but were, are revoked, and then
grant
the necessary permits are awarded.And so, little friends, we can have a common schema that everyone can consult but only root can modify.
until next time!