<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def create_mysql_db(db_url):
 """ To simplify deployment, create the mysql DB if it's not there. Accepts a URL with or without a DB name stated, and returns a db url containing the db name for use in the main sqlalchemy engine. THe formats can take the following form: mysql+driver://username:password@hostname mysql+driver://username:password@hostname/dbname if no DB name is specified, it is retrieved from config """


    #Remove trailing whitespace and forwardslashes
    db_url = db_url.strip().strip('/')


    #Check this is a mysql URL
    if db_url.find('mysql') >= 0:


        #Get the DB name from config and check if it's in the URL
        db_name = config.get('mysqld', 'db_name', 'hydradb')
        if db_url.find(db_name) >= 0:
            no_db_url = db_url.rsplit("/", 1)[0]
        else:
            #Check that there is a hostname specified, as we'll be using the '@' symbol soon..
            if db_url.find('@') == -1:
                raise HydraError("No Hostname specified in DB url")

            #Check if there's a DB name specified that's different to the one in config.
            host_and_db_name = db_url.split('@')[1]
            if host_and_db_name.find('/') >= 0:
                no_db_url, db_name = db_url.rsplit("/", 1)
            else:
                no_db_url = db_url
                db_url = no_db_url + "/" + db_name

        db_url = "{}?charset=utf8&use_unicode=1".format(db_url)

        if config.get('mysqld', 'auto_create', 'Y') == 'Y':
            tmp_engine = create_engine(no_db_url)
            log.warning("Creating database {0} as it does not exist.".format(db_name))
            tmp_engine.execute("CREATE DATABASE IF NOT EXISTS {0}".format(db_name))

    return db_url