title: How do I lock on an InnoDB row that doesn't exist yet?
body: <p>How can I guarantee that I can search if a username exists in my database, then insert that username into the database as a new row without any intercept between the <code>SELECT</code> and <code>INSERT</code> statements?</p>
  
  <p>Almost as if I am locking on a row that doesn't exist. I want to lock on the non-existent row with the username <em>"Foo"</em>, so that I can now check if it exists in the database AND insert it into the database if it doesn't already exist without any interruption.</p>
  
  <p>I know that using <code>LOCK IN SHARE MODE</code> and <code>FOR UPDATE</code> exist but as far as I know, that only works on rows that already exist. I am not sure what to do in this situation.</p>