iT邦幫忙

0

Laravel 7.x 無法遠端連線資料庫?

這是我在 .env 的設定

DB_CONNECTION=mysql
DB_HOST=xxx.xxx.xxx.xxx
DB_PORT=3306
DB_DATABASE=abc
DB_USERNAME=root
DB_PASSWORD=abc

xxx.xxx.xxx.xxx 是我server位置

我在我本地local下
mysql -u root -p -h xxx.xxx.xxx.xxx 試著遠端登入
是成功的

public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('email');
            $table->timestamps();
        });
    }

但我下 $ php artisan migrate 出現錯誤


   Illuminate\Database\QueryException 

  SQLSTATE[HY000] [1045] Access denied for user 'root'@'27-242-133-49.adsl.fetnet.net' (using password: YES) (SQL: select * from information_schema.tables where table_schema = abc and table_name = migrations and table_type = 'BASE TABLE')

有人有遇過嗎?

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中
0
小魚
iT邦大師 1 級 ‧ 2021-06-23 17:11:15

Access denied,
沒有權限,
如果資料庫是自己管的要查一下怎麼開,
如果不是自己管的,
請找負責人.

1

先確定你裏面有
root@27-242-133-49.adsl.fetnet.net
或是
root@%
這樣的帳號存在。

遠端連資料庫,注重的是後面那個像網址或IP的東西。
如果你本機的IP是 123.123.123.123
那你本機連過去的帳號就是

root@123.123.123.123

當然,直接設定%就代表全部了。

基本上,還有第二個可能性,就是IP被阻檔了。
不過依照你的錯誤訊息來看是不可能被擋的。
所以,你要先檢查好你遠端資料庫的帳號設定及權限是否正確。

不要去怪罪 Laravel 。它很無辜

0
混水摸魚
iT邦研究生 2 級 ‧ 2021-06-24 08:14:34

https://www.webteach.tw/?p=3685
這個給你參考參考。

我要發表回答

立即登入回答