title: Generate a random string in MySQL
body: <p>I'm trying to get a random string in phpmyadmin using a function. 
  I have the following code:</p>
  
  <pre><code>CREATE FUNCTION randomPassword()
  RETURNS varchar(128)
  BEGIN
  
      SET @chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
      SET @charLen = length(@chars);
  
      SET @randomPassword = '';
  
      WHILE length(@randomPassword) &lt; 12
          SET @randomPassword = concat(@randomPassword, substring(@chars,CEILING(RAND() * @charLen),1));
      END WHILE;
  
      RETURN @randomPassword ;
  END;
  </code></pre>
  
  <p>Now I get the error: </p>
  
  <blockquote>
    <p>1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 5</p>
  </blockquote>
  
  <p>Does anyone know how I can fix this?</p>