首页 > 解决方案 > SQLSTATE [HY000]:一般错误:1030 运行迁移时出现错误 168

问题描述

我通过composer安装了全新的laravel 7,创建了数据库并连接到.env。但是,当我运行迁移时,我看到以下错误:

    ➜  laravel-adp-4 git:(develop) ✗ php artisan migrate

   Illuminate\Database\QueryException

  SQLSTATE[HY000]: General error: 1030 Got error 168 - 'Unknown (generic) error from engine' from storage engine (SQL: create table `migrations` (`id` int unsigned not null auto_increment primary key, `migration` varchar(255) not null, `batch` int not null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')

我可以确认我的所有服务都已启动:

➜  laravel-adp-4 git:(develop) ✗ brew services list
Name      Status  User    Plist
mysql     started macbook /Users/macbook/Library/LaunchAgents/homebrew.mxcl.mysql.plist
mysql@5.7 started macbook /Users/macbook/Library/LaunchAgents/homebrew.mxcl.mysql@5.7.plist
nginx     started root    /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
php       started root    /Library/LaunchDaemons/homebrew.mxcl.php.plist
php@7.3   started macbook /Users/macbook/Library/LaunchAgents/homebrew.mxcl.php@7.3.plist

尝试进行故障排除时,我注意到我无法再操作 mysql。当我尝试创建另一个数据库时,我看到以下错误:

ERROR 3680 (HY000): Failed to create schema directory 'alala' (errno: 2 - No such file or directory)

为什么我无法运行迁移?为什么我无法创建数据库?

标签: mysqllaravel

解决方案


您的查询不正确,您的单引号太多了utf8mb4_unicode_ci

create table `migrations` (`id` int unsigned not null auto_increment primary key, `migration` varchar(255) not null, `batch` int not null) 
default character set utf8mb4 collate utf8mb4_unicode_ci

推荐阅读