davy_yg's avatar
Level 27

The user specified as a definer ('advancew'@'localhost') does not exist

Hello,

I get the following error message:

	SQLSTATE[HY000]: General error: 1449 The user specified as a definer ('advancew'@'localhost') does not exist (SQL: select * from `v_prod_images`) 

I wonder why?

ref: https://stackoverflow.com/questions/10169960/mysql-error-1449-the-user-specified-as-a-definer-does-not-exist

0 likes
4 replies
LaryAI's avatar
Level 58

The error message you're encountering, SQLSTATE[HY000]: General error: 1449 The user specified as a definer ('advancew'@'localhost') does not exist, typically occurs when a MySQL view, trigger, or stored procedure is defined by a user that no longer exists in the MySQL user table.

Here's a step-by-step solution to resolve this issue:

  1. Identify the View/Trigger/Procedure: Determine which view, trigger, or stored procedure is causing the issue. In your case, it seems to be related to the view v_prod_images.

  2. Check the Definer: You need to check the definer of the view. You can do this by querying the information_schema:

    SELECT DEFINER FROM information_schema.VIEWS WHERE TABLE_NAME = 'v_prod_images';
    
  3. Update the Definer: If the definer is indeed advancew@localhost and this user no longer exists, you need to update the definer to a valid user. You can do this by recreating the view with a new definer. First, get the view's definition:

    SHOW CREATE VIEW v_prod_images;
    

    This will give you the SQL statement used to create the view. It will look something like this:

    CREATE ALGORITHM=UNDEFINED DEFINER=`advancew`@`localhost` SQL SECURITY DEFINER VIEW `v_prod_images` AS SELECT ...
    
  4. Recreate the View: Use the definition obtained in the previous step to recreate the view with a new definer. For example, if you want to change the definer to root@localhost, you would do:

    CREATE OR REPLACE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v_prod_images` AS SELECT ...;
    

    Make sure to replace the SELECT ... part with the actual select statement from the SHOW CREATE VIEW output.

  5. Verify the Change: Finally, verify that the definer has been updated:

    SELECT DEFINER FROM information_schema.VIEWS WHERE TABLE_NAME = 'v_prod_images';
    

Here is a complete example assuming the view definition is simple:

-- Step 1: Check the current definer
SELECT DEFINER FROM information_schema.VIEWS WHERE TABLE_NAME = 'v_prod_images';

-- Step 2: Get the view definition
SHOW CREATE VIEW v_prod_images;

-- Step 3: Recreate the view with a new definer
CREATE OR REPLACE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v_prod_images` AS SELECT * FROM `prod_images`;

-- Step 4: Verify the change
SELECT DEFINER FROM information_schema.VIEWS WHERE TABLE_NAME = 'v_prod_images';

By following these steps, you should be able to resolve the error and ensure that the view v_prod_images is defined by a valid user.

jlrdw's avatar

I meant when backing up, backup routines also.

And a user needs to be created for the routine in question, but two separate things, I was just reminding them to backup with routines.

Original deleted cause it did sound confusing.

Please or to participate in this conversation.