title: RENAME USER in a stored procedure
body: <p>I'm trying to create a stored procedure to rename users in my MySQL database:</p>
  
  <pre><code>CREATE DEFINER=`admin`@`%` PROCEDURE `renamedbuser`(
    IN _oldname VARCHAR(200),
    IN _newname VARCHAR(200)
  )
  BEGIN
    IF (SELECT COUNT(User) FROM mysql.user WHERE User = _oldname) &gt; 0 THEN
    BEGIN
      RENAME USER _oldname TO _newname;
    END;
    END IF;
  END
  </code></pre>
  
  <p>When I run this procedure I get the following error:</p>
  
  <pre><code>MySql.Data.MySqlClient.MySqlException (0x80004005): Operation RENAME USER failed for '_oldname'@'%'
  </code></pre>
  
  <p>It seems to me that when the RENAME USER line executes, it uses the <em>name</em> of the variable _oldname as the original username, rather than the <em>value</em> that the variable contains.</p>
  
  <p>If I execute something like</p>
  
  <pre><code>RENAME USER 'test' TO 'testing';
  </code></pre>
  
  <p>If works as I'd expect, renaming the 'test'@'%' user.</p>
  
  <p>Am I calling RENAME USER incorrectly? Does that statement just not work this way when called from a stored procedure? Is there any way to achieve the behavior I'm looking for?</p>