我的任务是在我的工作站上设置Laravel,它已经非常复杂了。
在设置MySQL时,我收到以下错误:
Illuminate\Database\QueryException : SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from information_schema.tables where table_schema = techpocket and table_name = migrations)
at /Users/George/Sites/TechPocketnews/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664
660| // If an exception occurs when attempting to run a query, we'll format the error
661| // message to include the bindings with SQL, which will make this exception a
662| // lot more helpful to the developer instead of just the database's errors.
663| catch (Exception $e) {
> 664| throw new QueryException(
665| $query, $this->prepareBindings($bindings), $e
666| );
667| }
668|
Exception trace:
1 PDOException::("SQLSTATE[HY000] [2002] No such file or directory")
/Users/George/Sites/TechPocketnews/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:68
2 PDO::__construct("mysql:unix_socket=/Applications/MAMP/tmp/mysql/mysql.sock;dbname=techpocket", "root", "", [])
/Users/George/Sites/TechPocketnews/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:68
Please use the argument -v to see more details.
当我尝试运行命令时:
php artisan migrate
下面是我在app / config / database.php文件中的mysql配置:
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', '/Applications/MAMP/tmp/mysql/mysql.sock'),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
下面是我在.env文件中的mysql配置:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=techpocket
DB_USERNAME=root
DB_PASSWORD=
我是Laravel的新手,很高兴:)
感谢您的帮助。
旁注:我正在运行PHP 7.1.7,MySQL 8.11和Laravel 5.4
答案 0 :(得分:0)
由于我正在使用MAMP,因此发生了同样的问题。我在laravel 5.7上,所以我的database.php在mysql指令下有以下一行:
'unix_socket'=> env('DB_SOCKET',''),
解决方案是添加环境文件中缺少的DB_SOCKET选项:
DB_SOCKET = /应用程序/MAMP/tmp/mysql/mysql.sock
答案 1 :(得分:-1)
添加到app / Providers / AppServiceProviders.php:
use Illuminate\Support\Facades\Schema;
public function boot()
{
Schema::defaultStringLength(191);
}
检查一下。希望它有效。
注意:您仍然收到错误添加
DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock
<。>在.env文件中。