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
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)

$this->wrapValue($name),
$this->wrapValue($connection->getConfig('charset')),
$this->wrapValue($connection->getConfig('collation')),
! empty($collation) ? $this->wrapValue($collation) : $collation,
);
}

Expand Down