DELIMITER $$

DROP FUNCTION IF EXISTS get_database_storage_size;$$

CREATE FUNCTION get_database_storage_size(dbName VARCHAR (255))
    RETURNS BIGINT
DETERMINISTIC
READS SQL DATA
BEGIN
    DECLARE
size BIGINT;
SELECT SUM(data_length + index_length)
INTO size
FROM information_schema.TABLES
WHERE table_schema = dbName;

RETURN
size;
END;$$

DELIMITER ;