php - Laravel项目如何远程连接mysql数据库

标签 php mysql laravel

我正在尝试将我的 Laravel"(本地设置)项目与 cPanel Mysql 远程连接。但我遇到了问题。请帮我解决这个问题

已允许管理 SSH,并且我连接了 SSH 隧道。

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=rashgsen_bdskills
DB_USERNAME=rashgsen_skills
DB_PASSWORD=B*****1desh@2020

当我尝试运行 php artisan migrate 时,它不起作用。错误显示。

SQLSTATE[HY000] [1045] Access denied for user 'rashgsen_skills'
@'localhost' (using password: YES) (SQL: select * from information_schema.tables where table_schema = ra
shgsen_bdskills and table_name = migrations and table_type = 'BASE TABLE')

  at F:\xamppnew\htdocs\laravel\skillsbd\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] [1045] Access denied for user 'rashgsen_skills'@'localhost' (using
 password: YES)")
      F:\xamppnew\htdocs\laravel\skillsbd\vendor\laravel\framework\src\Illuminate\Database\Connectors\Co
nnector.php:70

  2   PDO::__construct("mysql:host=127.0.0.1;port=3306;dbname=rashgsen_bdskills", "rashgsen_skills", "Ba*****esh@2020", [])
      F:\xamppnew\htdocs\laravel\skillsbd\vendor\laravel\framework\src\Illuminate\Database\Connectors\Co
nnector.php:70

最佳答案

你的环境应该是这样的

DB_CONNECTION=mysql
DB_HOST=     // your cpanel domain ip address which u can see in statistics 
DB_PORT=3306
DB_DATABASE= // cpanel mysql db name
DB_USERNAME= // cpanel mysql user
DB_PASSWORD= // cpanel mysql pssword

最后一步找到你的电脑 ip 地址并将其添加到 cpanel Romote Mysql

关于php - Laravel项目如何远程连接mysql数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57844682/

相关文章:

php - 使用套接字php的UDP端口扫描程序

php - 选择日期之前

mysql - 操作数应包含 1 列

laravel - 在 Laravel - 使用 ubuntu 16.04 在 xampp 上找不到驱动程序

Laravel - 忘记参数

php - 整个网站显示为怪异字符

php - Symfony:定义作用域 HttpClient 类

mysql - 如何计算拥有超过 1 个订单的用户?

java - 结构变化的休假报告的数据库架构

php - Laravel Eloquent skip n, take all?