title: Python error 1064 on mysqlconnector Create Statement
body: <p>I am attempting to create a small database where the user can at will create a new database to store information. </p>
  
  <p>I am trying to take the users input and run a CREATE DATABASE IF NOT EXISTS, however I appear to be running into a problem where I get a 1064(42000) error. </p>
  
  <p>Specifically it reads:</p>
  
  <blockquote>
    <p>mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use new ''test_client'' at line 1. </p>
  </blockquote>
  
  <p>I have a separate class which is called build that is specifically used to create a database or a table at the request of the user. </p>
  
  <p>The issue here is that I have one method of code that works and another that does not. I am trying to learn what is causing this issue as I am trying to ensure that the code is protected from any sql injections. </p>
  
  <p>I have tried to write the code in two ways:</p>
  
  <ol>
  <li>The users input is stored in a variable called 'name'. 
  I have a piece of code that add's a '_' if there are any white spaces in the name. 
  I have a variable (called sqlFormula) which houses the code:
  These are both then run into a mycursor.execute.
  And this is where I get the error. </li>
  </ol>
  
  <p>Code:</p>
  
  <pre><code>    name = re.sub("\s+", "_", name)
      sqlFormula = ("""CREATE DATABASE IF NOT EXISTS %s""")
      mycursor.execute(sqlFormula, (name,))
  </code></pre>
  
  <p>This is the version that yields the error.</p>
  
  <ol start="2">
  <li><p>The second way, which works is by doing the following:</p></li>
  </ol>
  
  <pre><code>    name =  = re.sub("\s+", "_", name)
      sqlFormula = """CREATE DATABASE IF NOT EXISTS %s"""%name
      mycursor.execute(sqlFormula)
  </code></pre>
  
  <p>This does not yield an error. </p>
  
  <p>The partial codes that are involved in this part are below:</p>
  
  <pre><code>class Build():
      __slots__ = ['userentry', 'database']
  
      def __init__ (self, used_database, user_entry = None)
          self.database = used_database
          self.userentry = user_entry
  
      def create_database (self)
          mycursor = self.database.cursor()
          name = re.sub("\s+", "_", name)
          sqlFormula = ("""CREATE DATABASE IF NOT EXISTS %s""")
          mycursor.execute(sqlFormula, (name,))
          mycursor.close()
  
  class Create()
      def Create_table():
          user_input = input("What is the name of the database to create?")
          #a separate variable called db is used to house the db connection.
          Build(db, user_input).create_database()
  
  
  I expected that by using the variable name in a tuple and the %s placeholder, that it would work without any problem. However I just keep getting the error.
  </code></pre>