While loop on mysql DB
<p>First of all, sorry for my noobish question, because I'm pretty sure it is.</p>

<p>I'm using MySQL 5.5.53 on an Ubuntu 14.04.</p>

<p>I'm trying to delete all users with a username starting with the letter "z" from a database. But I also need to delete their rights and remove them from the group they belong too.</p>

<p>The only common point between these tables is the user_id in the user table.</p>

<p>Below, this is the method I'm trying to use to delete a user. Once it works for it, it'll be easy as abc for the other tables.</p>

<p>Unfortunately for this does not work:</p>

<p>I create a file "clearusers.sql":</p>

<pre><code>CREATE PROCEDURE clearusers()
BEGIN
        SELECT @count := COUNT(*) FROM db_user WHERE username like 'z%';
        WHILE @count &gt; 0 DO
                SELECT @user_id := user_id FROM db_user WHERE username LIKE 'z%' LIMIT 1;
                delete * from db_user where user_id = @user_id;
                @count = @count -1;
        END WHILE;
END;
</code></pre>

<p>Then I do this:</p>

<blockquote>
  <p>mysql -u root -p mysqldb &lt; clearusers.sql</p>
</blockquote>

<p>Then I get this error:</p>

<blockquote>
  <p>ERROR 1064 (42000) at line 1: 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 3</p>
</blockquote>

<p>I don't know what I'm doing wrong. So to anybody : Thanks by advance for your help.</p>

<p>Proc.</p>