MySQL error 1449: The user specified as a definer does not exist
Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.
Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Problem
After moving a MySQL database between MySQL servers we observe the following error on atlassian-confluence.log
files when trying to edit pages:
caused by: org.springframework.jdbc.UncategorizedSQLException: Hibernate operation: could not execute statement; uncategorized SQLException; SQL state [HY000]; error code [1449]; The user specified as a definer ('username'@'hostname') does not exist; nested exception is java.sql.SQLException: The user specified as a definer ('username'@'hostname') does not exist
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:89)
caused by: java.sql.SQLException: The user specified as a definer ('username'@'hostname') does not exist
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
Diagnosis
Environment
- This issue affects Confluence with MySQL version 5.7 and 8.0.
Cause
“The DEFINER
clause specifies the MySQL account to be used when checking access privileges at routine execution time for routines that have the SQL SECURITY DEFINER
characteristic.”
When a procedure is exported into a Dump File, it is exported having username and hostname defined in its DDL. The combination of username and hostname is the DEFINER that has permissions to run that procedure.
Error will happen if that dump is imported into a Database without the combination of username and hostname with privileges granted on the new database.
Resolution
There are few possible solutions, it will all depend on your environment and which MySQL version you are running.
Always back up your data before performing any modifications to the database. If possible, test any alter, insert, update, or delete SQL commands on a staging server first.
The following SQL statements should be run whilst Confluence is shutdown.
Solution 1
Create the missing user/account and grant permission for 'username'@'hostname'
Even if you are not planning to use that user for Confluence to connect to MySQL, that user will be used by MySQL to run the Procedures with thatDEFINER
:CREATE USER IF NOT EXISTS <username> IDENTIFIED BY '<password>'; GRANT ALL PRIVILEGES ON <ConfluenceDatabase>.* TO '<username>'@'<hostname>';
Solution 2
Alter MySQL Dump File before import
As mentioned above, procedures were exported from previous MySQL with DEFINER set for '<username>'@'<hostname>'.
After export the Dump File, you should modify dump file, looking for previous username/hostname combination on Create Procedure statements and replace with new username and hostname. And finally import Dump File on new MySQL server.
Solution 3
3.1. Fix up the Stored Procedures Definers:
3.2. Fix up the Triggers Definers:
Solution 4
Migrate Database
You can use the Documentation used to Migrate databases. This can be used to move Databases from one server to another, even if you are using same database on both server, like MySQL: Migrating to Another Database