mariadb/mysql-test/main/create_or_replace_permission.result
Sergei Golubchik e3d9369774 cleanup: disconnect before DROP USER
let's always disconnect a user connection before dropping the said user.
MariaDB is traditionally very tolerant to active connections
of the dropped user, which isn't the case for most other databases.

Let's avoid unintentionally spreading incompatible behavior
and disconnect before drop.

Except in cases when the test specifically tests such a behavior.
2025-07-16 09:14:33 +07:00

53 lines
2.3 KiB
Text

set local sql_mode="";
set global sql_mode="";
#
# Tests for checking permission denied on CREATE OR REPLACE if DROP
# access is revoked
#
# These statements do not need special tests for CREATE OR REPLACE,
# because they do not have separate permissions for create and drop:
# CREATE OR REPLACE EVENT (uses EVENT_ACL for both CREATE and DROP)
# CREATE OR DROP SERVER (uses SUPER_ALC for both CREATE and DROP)
# CREATE OR DROP TRIGGER (uses TRIGGER_ACL for both CREATE and DROP)
SELECT CURRENT_USER;
CURRENT_USER
root@localhost
CREATE DATABASE db1;
GRANT ALL ON db1.* TO mysqltest_1@localhost;
REVOKE DROP ON db1.* FROM mysqltest_1@localhost;
REVOKE ALTER ROUTINE ON db1.* FROM mysqltest_1@localhost;
GRANT DELETE ON mysql.* TO mysqltest_1@localhost;
REVOKE DELETE ON mysql.* FROM mysqltest_1@localhost;
FLUSH PRIVILEGES;
connect user_a, localhost, mysqltest_1,,;
connection user_a;
SELECT CURRENT_USER;
CURRENT_USER
mysqltest_1@localhost
CREATE DATABASE db1;
ERROR HY000: Can't create database 'db1'; database exists
CREATE OR REPLACE DATABASE db1;
ERROR 42000: Access denied for user 'mysqltest_1'@'localhost' to database 'db1'
CREATE OR REPLACE DATABASE db2;
ERROR 42000: Access denied for user 'mysqltest_1'@'localhost' to database 'db2'
USE db1;
CREATE OR REPLACE TABLE t1(id INT);
ERROR 42000: DROP command denied to user 'mysqltest_1'@'localhost' for table `db1`.`t1`
CREATE OR REPLACE PROCEDURE proc1 (OUT cnt INT) BEGIN END;
ERROR 42000: alter routine command denied to user 'mysqltest_1'@'localhost' for routine 'db1.proc1'
CREATE OR REPLACE FUNCTION lookup RETURNS STRING SONAME "UDF_EXAMPLE_LIB";
ERROR 42000: Access denied for user 'mysqltest_1'@'localhost' to database 'mysql'
CREATE OR REPLACE FUNCTION hello(str char(20)) RETURNS TEXT RETURN CONCAT('Hello, ', str, '!');
ERROR 42000: alter routine command denied to user 'mysqltest_1'@'localhost' for routine 'db1.hello'
CREATE OR REPLACE USER u1@localhost;
ERROR 42000: Access denied; you need (at least one of) the CREATE USER privilege(s) for this operation
CREATE OR REPLACE ROLE developer;
ERROR 42000: Access denied; you need (at least one of) the CREATE USER privilege(s) for this operation
connection default;
disconnect user_a;
SELECT CURRENT_USER;
CURRENT_USER
root@localhost
DROP DATABASE db1;
DROP USER mysqltest_1@localhost;
set global sql_mode=default;