title: How to declare variable in MySql?
body: <p>Here is my table:</p>
  
  <p>Id  Name   Count</p>
  
  <p>1   Apple  1</p>
  
  <p>2   Peach  1</p>
  
  <p>If I just have Name and MySql which is set to "Safe Update Mode"(under this mode, can't update table with out key in where terms). So I need get Id by Name at first, then update row.</p>
  
  <p>In SqlServer, I can do it like below:</p>
  
  <pre><code>DELCARE @Id INT;
  SELECT @Id=(SELECT Id FROM MyTable WHERE Name='Apple')
  
  IF(@Id IS NOT NULL)
  BEGIN
    UPDATE MyTable
      SET Count=2
    WHERE Id=@Id
  END
  </code></pre>
  
  <p>In MySql, how can I do?</p>