dqce48404 2017-05-02 01:30
浏览 175
已采纳

如何查看配置文件中的MySQL / MariaDB版本?

The issue I run into is that when I run my database migrations I get an error when the charset is utf8mb4 due to this line and some other indexes:

$table->string('taggable_type', 255)->index();

So, I thought that if I can modify the charset that is being used to utf8 in config/database.php by checking which MySQL version is used, the issue can be solved/worked around.

I was thinking about doing a raw query like:

\Illuminate\Support\Facades\DB::raw('SHOW VARIABLES LIKE "%version%"');

inside config/database.php. Now that error I receive is that

A facade root has not been set.

How can I solve this issue?

Yes, I have tried setting Schema::defaultStringLength(191); inside the boot method of my AppServiceProvider and I have also tried 'engine' => 'InnoDB ROW_FORMAT=DYNAMIC', but I still receive that the specified key is too long which I believe might be due to MySQL 5.5 I believe.

Any help as to how I can check the MySQL version inside a config file or a hint to a different approach would be highly appreciated.

  • 写回答

2条回答 默认 最新

  • douyanjing8287 2017-05-02 05:58
    关注

    The following is available since 5.5.14.

    1. Set innodb_file_format=Barracuda
    2. Set innodb_large_prefix=1

    This also requires the 'engine' => 'innodb row_format=dynamic' which you've mentioned that you're already using. I am repeating it here for completeness.

    Newer mysql versions (>=5.7.9) has a innodb_default_row_format=dynamic which can be used instead of the config change.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?