我的任务是在我的工作站上设置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的新手,友好点
感谢你的帮助。
Sidenote:我正在运行PHP7.1.7、MySQL 8.11和Laravel5.4
发布于 2018-11-29 18:07:51
因为我用的是MAMP,所以也有同样的问题。我在Laravel5.7上,所以我的database.php在mysql指令下有这一行:
'unix_socket‘=> env('DB_SOCKET',''),
解决方案是添加环境文件中缺少的DB_SOCKET选项:
DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock
发布于 2018-06-16 07:29:46
添加到app/Providers/AppServiceProviders.php:
use Illuminate\Support\Facades\Schema;
public function boot()
{
Schema::defaultStringLength(191);
}看看这个。希望它能成功。
注意到:仍然有错误添加
DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock在.env文件中。
https://stackoverflow.com/questions/50882927
复制相似问题