In MariaDB, standard account permissions do not support setting field-level write-only access directly. Permissions are typically granted at the table level (e.g., SELECT, INSERT, UPDATE, DELETE) or column level (e.g., INSERT(column_name), UPDATE(column_name)), but there is no built-in privilege to allow updates while explicitly denying reads for a specific field.
However, you can achieve a similar effect using a combination of views and stored procedures:
INSERT and UPDATE permissions on the table but deny SELECT.SELECT on the view instead of the table.EXECUTE permission while keeping table permissions minimal.Example:
-- Create a table
CREATE TABLE users (id INT, username VARCHAR(50), password_hash VARCHAR(255));
-- Grant insert/update but deny select on the table
GRANT INSERT, UPDATE ON users TO 'app_user'@'%';
REVOKE SELECT ON users FROM 'app_user'@'%';
-- Create a view excluding the sensitive field
CREATE VIEW users_view AS SELECT id, username FROM users;
-- Grant select on the view
GRANT SELECT ON users_view TO 'app_user'@'%';
For more advanced scenarios, Tencent Cloud Database for MariaDB provides fine-grained access control through its security groups and privilege management, allowing you to restrict access at the network and account levels. Additionally, Tencent Cloud TDSQL-C (a high-performance MariaDB-compatible database) supports automated backups and encryption, enhancing data security.