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 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题
  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码