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'@'*******' (using password: YES) (SQL: select * from information_schema.tables where table_schema = abc and table_name = migrations and table_type = 'BASE TABLE')

我的phpmyadmin 已經設置帳戶
Screen Shot 2021-06-25 at 1.57.36 AM.png

有人有遇過嗎?

阅读 1.4k
1 个回答

Mysql分配用户权限

grant all privileges on *.* to root@'%' identified by 'root' WITH GRANT OPTION;

flush privileges;
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题