Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes unable to create MySQL database with null collation using Schema::createDatabase() #48886

Closed
wants to merge 1 commit into from

Conversation

crynobone
Copy link
Member

…hema::createDatabase()`

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
@@ -43,11 +43,13 @@ class MySqlGrammar extends Grammar
*/
public function compileCreateDatabase($name, $connection)
{
$collation = $connection->getConfig('collation');

return sprintf(
'create database %s default character set %s default collate %s',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Jubeki can you confirm this can generate the correct SQL?

Copy link
Contributor

@Jubeki Jubeki Nov 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like for Mysql this results in the following:

use Illuminate\Database\Schema\Grammars\MySqlGrammar;

$grammar = new MySqlGrammar();
return $grammar->compileCreateDatabase('test', DB::connection());

// create database `test` default character set `utf8mb4` default collate

Result of execution of the sql query:

ERROR 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 near '' at line 1

(I will also take a look at the linked issue later today)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested the current laravel/laravel against Laravel Sail, I don't have any other DB on may Laptop.

Simplest solution would probably be to revert my PR @crynobone, and simply add another config entry for Laravel 11. (see my framework PR)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Jubeki just something to consider for Laravel 11, Schema::createDatabase() is used in Parallel testing and similar issue will still persist in Laravel 11 if collation configuration is null.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, for Laravel 11 was the idea to create the new mariadb config entry with the default collation set for both mariadb and mysql. (see #48455)

@taylorotwell
Copy link
Member

Reverted laravel/laravel#6241

@taylorotwell taylorotwell deleted the fixes-create-db branch November 2, 2023 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants