![](/img/trans.png)
[英]SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from information_schema.tables where table_schema = home and table_name = migrations)
[英]Connection refused SQL: select * from information_schema.tables where table_schema = firstdb and table_name = migrations and table_type = 'BASE TABLE
我安裝並打開了 XAMPP,這就是我訪問 phpmyadmin 頁面的方式。 我在 phpmyadmin 中創建了一個名為“firstdb”的數據庫。
我還在本地存儲的 laravel 文件中創建了 auth。 我正在嘗試使用 php artisan migrate 遷移表,但出現以下錯誤。
user@Andress-MacBook-Pro admin-panel % php artisan migrate
Illuminate\Database\QueryException
SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = firstdb and table_name = migrations and table_type = 'BASE TABLE')
at vendor/laravel/framework/src/Illuminate/Database/Connection.php:671
667| // If an exception occurs when attempting to run a query, we'll format the error
668| // message to include the bindings with SQL, which will make this exception a
669| // lot more helpful to the developer instead of just the database's errors.
670| catch (Exception $e) {
> 671| throw new QueryException(
672| $query, $this->prepareBindings($bindings), $e
673| );
674| }
675|
+37 vendor frames
38 artisan:37
Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
我到處都看過了,請幫忙。
可能是.env
文件中的 mysql 端口號錯誤。 檢查您的.env
文件並確保端口號與 mysql 正在使用的端口號匹配。
我注意到命令行 output 中的密碼與 env 文件中的實際密碼有些奇怪。 原來我的密碼中有一個數字符號,它被切斷了。
因此,在運行php artisan migrate
后檢查 output 並確保密碼與您的環境中的密碼實際匹配(以及與此相關的所有信息)。 解決方法是在不匹配的情況下添加引號。
DB_PASSWORD=abcdefghijklmonp5#Q
會成為
DB_PASSWORD='abcdefghijklmonp5#Q'
當您使用 DB/QueryBuilder 時,Laravel 會進行此類查詢。 當您使用 Model 並在那里填充可填充屬性數組然后代碼
$model::create(['id' => 1]);
將只插入 $model 的表中。 如果您不填充可填充(保護)數組 Db QueryBuilder 將通過執行檢查此表中是否存在此類列
"select column_name as `column_name` from information_schema.columns where table_schema = ? and table_name = ?"
然后才執行插入。 建議 - 使用 $model->save() 而不是 $model::create,或為 model 填充可填充屬性
除了確保您的所有配置都是正確的 escaping 密碼和引號之外,我在 linux 上的全新安裝中遇到了類似的問題。
SQLSTATE[HY000] [1045] 用戶'username'@'localhost'的訪問被拒絕(使用密碼:YES)(SQL:select * from information_schema.tables where table_schema = studentaffairs and table_name = migrations and table_type = 'BASE TABLE')
為了解決這個問題,我確保運行composer update
並且我運行了npm run dev
然后它能夠毫無問題地遷移。
嘗試將 your.env 上的 DB_HOST 設置為
DB_HOST=localhost
首先,檢查用戶插件:
mysql> SELECT User,Host,plugin FROM mysql.user WHERE user='root';
如果用戶正在使用 caching_sha2_password 更改為mysql_native_password ,因為 PHP 還不了解 caching_sha2_password
mysql>ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password'
為了設置數據庫主機,您需要編輯 .env 文件並指定所需的主機名而不是 IP 地址。 為此,請在.env文件中找到 DB_HOST 變量並為其分配值“localhost”。 這將指示您的應用程序連接到本地數據庫服務器,該服務器通常與應用程序本身運行在同一台機器上。
例如,您可能會在 .env 文件中看到這樣一行:
DB_HOST=
要將主機名設置為“localhost”,您只需將行更新為:
DB_HOST=localhost
將更改保存到 .env 文件后,您的應用程序應該能夠使用您指定的主機名或 IP 地址連接到本地數據庫服務器。
在.env
文件中將 DB_CONNECTION=127.0.0.7 更改為 mysql
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.