mirror of
https://github.com/MariaDB/server.git
synced 2025-01-16 03:52:35 +01:00
e9572e53e6
From 10.4.13, the `mariadb.sys` user was created to replace `root` definers.
- In commit 0253ea7f22
, definer of
Add/DropGeometryColumn procedures was changed to `mariadb.sys`, in
`scripts/maria_add_gis_sp.sql.in`.
However, maria_add_gis_sp.sql only applies to new databases created by
installation script. Databases upgraded from old versions will miss this
change.
- In addition, according to commit
0d6d801e5886208b2632247d88da106a543e1032(MDEV-23102), in some scenarios
when root user is replaced it will skip creating `mariadb.sys` user.
This commit is to update the definer from `root` to `mariadb.sys` during
upgrade. It only makes the change if the original definers are root.
Doesn't choose to execute `maria_add_gis_sp.sql` in upgrade script to
recreate the procedures is because of considering the scenarios of
MDEV-23102 that `root` user is replaced and `mariadb.sys` is not created.
All new code of the whole pull request, including one or several files
that are either new files or modified ones, are contributed under the
BSD-new license. I am contributing on behalf of my employer Amazon Web
Services, Inc.
66 lines
3.1 KiB
Text
66 lines
3.1 KiB
Text
--echo #
|
|
--echo # The definer of Add/DropGeometryColumn procedures should be updated to mariadb.sys during upgrade
|
|
--echo #
|
|
|
|
--source include/mysql_upgrade_preparation.inc
|
|
|
|
use mysql;
|
|
|
|
create table save_proc like proc;
|
|
insert into save_proc select * from proc;
|
|
set @save_sql_mode= @@sql_mode;
|
|
|
|
--echo #
|
|
--echo # If the definer is root before the upgrade:
|
|
--echo # Drop the procedures if exists and recreate with root definer
|
|
--echo #
|
|
DROP PROCEDURE IF EXISTS AddGeometryColumn;
|
|
DROP PROCEDURE IF EXISTS DropGeometryColumn;
|
|
|
|
DELIMITER |;
|
|
|
|
CREATE DEFINER=`root`@`localhost` PROCEDURE AddGeometryColumn(catalog varchar(64), t_schema varchar(64),
|
|
t_name varchar(64), geometry_column varchar(64), t_srid int) SQL SECURITY INVOKER
|
|
begin
|
|
set @qwe= concat('ALTER TABLE ', t_schema, '.', t_name, ' ADD ', geometry_column,' GEOMETRY REF_SYSTEM_ID=', t_srid); PREPARE ls from @qwe; execute ls; deallocate prepare ls; end |
|
|
|
|
CREATE DEFINER=`root`@`localhost` PROCEDURE DropGeometryColumn(catalog varchar(64), t_schema varchar(64),
|
|
t_name varchar(64), geometry_column varchar(64)) SQL SECURITY INVOKER
|
|
begin
|
|
set @qwe= concat('ALTER TABLE ', t_schema, '.', t_name, ' DROP ', geometry_column); PREPARE ls from @qwe; execute ls; deallocate prepare ls; end |
|
|
|
|
DELIMITER ;|
|
|
|
|
SELECT count(*) FROM information_schema.ROUTINES WHERE ROUTINE_CATALOG = 'def' and ROUTINE_SCHEMA = 'mysql' and ROUTINE_NAME='AddGeometryColumn' and DEFINER = 'root@localhost';
|
|
SELECT count(*) FROM information_schema.ROUTINES WHERE ROUTINE_CATALOG = 'def' and ROUTINE_SCHEMA = 'mysql' and ROUTINE_NAME='DropGeometryColumn' and DEFINER = 'root@localhost';
|
|
|
|
SELECT count(*) FROM information_schema.ROUTINES WHERE ROUTINE_CATALOG = 'def' and ROUTINE_SCHEMA = 'mysql' and ROUTINE_NAME='AddGeometryColumn' and DEFINER = 'mariadb.sys@localhost';
|
|
SELECT count(*) FROM information_schema.ROUTINES WHERE ROUTINE_CATALOG = 'def' and ROUTINE_SCHEMA = 'mysql' and ROUTINE_NAME='DropGeometryColumn' and DEFINER = 'mariadb.sys@localhost';
|
|
|
|
let $MYSQLD_DATADIR= `select @@datadir`;
|
|
|
|
--echo #
|
|
--echo # Run mysql_upgrade
|
|
--echo #
|
|
--exec $MYSQL_UPGRADE 2>&1
|
|
--file_exists $MYSQLD_DATADIR/mysql_upgrade_info
|
|
--remove_file $MYSQLD_DATADIR/mysql_upgrade_info
|
|
|
|
--echo #
|
|
--echo # check new definers of Add/DropGeometryColumn
|
|
--echo #
|
|
SELECT count(*) FROM information_schema.ROUTINES WHERE ROUTINE_CATALOG = 'def' and ROUTINE_SCHEMA = 'mysql' and ROUTINE_NAME='AddGeometryColumn' and DEFINER = 'root@localhost';
|
|
SELECT count(*) FROM information_schema.ROUTINES WHERE ROUTINE_CATALOG = 'def' and ROUTINE_SCHEMA = 'mysql' and ROUTINE_NAME='DropGeometryColumn' and DEFINER = 'root@localhost';
|
|
|
|
SELECT count(*) FROM information_schema.ROUTINES WHERE ROUTINE_CATALOG = 'def' and ROUTINE_SCHEMA = 'mysql' and ROUTINE_NAME='AddGeometryColumn' and DEFINER = 'mariadb.sys@localhost';
|
|
SELECT count(*) FROM information_schema.ROUTINES WHERE ROUTINE_CATALOG = 'def' and ROUTINE_SCHEMA = 'mysql' and ROUTINE_NAME='DropGeometryColumn' and DEFINER = 'mariadb.sys@localhost';
|
|
|
|
--echo #
|
|
--echo # restore environment
|
|
--echo #
|
|
delete from proc;
|
|
rename table proc to bad_proc;
|
|
rename table save_proc to proc;
|
|
drop table bad_proc;
|
|
flush privileges;
|
|
|