Support the ongoing development of Laravel.io →
Configuration Database Queues

So I made the rookie mistake of putting a dash in the name of my MySQL database (ie My-Database ). After upgrading to Laravel 4.2, none of my repos worked. Here’s what I discovered:

  1. Don’t put a dash in your db name…use an underscore. Duh.

  2. If you have a dash in the name, and are getting errors as I did, the error is being thrown from: Illuminate\Database\Connectors\MySqlConnector line 26 using the "connect" method. This method picks up (verbatim) the database name you specified in the app/config/database.php file.

  3. In order to bypass the error, single quotes (tilde key) must be added to the db name .

  4. Adding the quotes to the db name within the app/config/database.php file does not work.

  5. The following snippet within the Illuminate\Database\Connectors\MySqlConnector "connect" method solved the problem:

Original (starting at line 22):

if (isset($config['unix_socket']))

{

    $connection->exec("use {$config['database']};");

}

Modified:

if (isset($config['unix_socket']))

{

    $dbName = $config['database'];

    if(strpos($dbName, '-')) // if the db name contains a dash
    {
   
        $config['database'] = '`'.$dbName.'`'; //add single quotes to db name

    }
 
    $connection->exec("use {$config['database']};"); 

}

If anyone has a tidier way of approaching this, I would love the feedback.

Thanks! Chris

Last updated 3 years ago.
0

You don't have to check if a dash exists, you should be able to just add the ticks regardless.

Last updated 3 years ago.
0

@DrPrez: I attempted a name change using a similar method to the one you posted. I actually just completed the name change successfully using the terminal with the following command line:

mysqldump -uroot -proot --protocol=socket -S mysql.sock My-Database | mysql -uroot -proot --protocol=socket -S mysql.sock my_database

I was treading lightly as I have active records that I did not want to lose, but this method worked nicely. Thanks for the feedback.

Chris

Last updated 3 years ago.
0

@aheinzm: I thought the same thing, but apparently the ticks are not picked up or added to the value that is placed in the app/config/database.php file. I'm learning the ropes, so everyday is a journey. Thanks for the feedback.

Chris

Last updated 3 years ago.
0

Sign in to participate in this thread!

PHPverse

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.