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条)

报告相同问题?

悬赏问题

  • ¥15 软件定义网络mininet和onos控制器问题
  • ¥15 微信小程序 用oss下载 aliyun-oss-sdk-6.18.0.min client报错
  • ¥15 ArcGIS批量裁剪
  • ¥15 labview程序设计
  • ¥15 为什么在配置Linux系统的时候执行脚本总是出现E: Failed to fetch http:L/cn.archive.ubuntu.com
  • ¥15 Cloudreve保存用户组存储空间大小时报错
  • ¥15 伪标签为什么不能作为弱监督语义分割的结果?
  • ¥15 编一个判断一个区间范围内的数字的个位数的立方和是否等于其本身的程序在输入第1组数据后卡住了(语言-c语言)
  • ¥15 Mac版Fiddler Everywhere4.0.1提示强制更新
  • ¥15 android 集成sentry上报时报错。