MAMP Pro OSX上的Laravel远程数据库连接问题 [英] Laravel remote DB connection issue on MAMP Pro OSX

查看:161
本文介绍了MAMP Pro OSX上的Laravel远程数据库连接问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Laravel上已有一个项目.我想与远程数据库服务器建立连接,以便我们的团队可以使用相同的数据集进行测试.

I have an existing project on Laravel. I want to make a connection to remote DB server so our team can test with the same set of data .

.ENV文件

APP_NAME=Laravel
APP_ENV=live
APP_KEY=base64:FE9rhqH/+5UHVJCfoYS6xHNsU9U1DJaPkUDmRSv6JxI=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://laravel.test/

DB_CONNECTION=mysql
DB_HOST=104.1XX.XX.XX
DB_PORT=3306
DB_DATABASE=My_db_name
DB_USERNAME=db_username
DB_PASSWORD=db_password
DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock

BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
SESSION_LIFETIME=120
QUEUE_DRIVER=sync

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=

database.php

database.php

'mysql' => [
        'driver' => 'mysql',
        'host' => env('DB_HOST', '104.1XX.XX.XX'),
        'port' => env('DB_PORT', ''),
        'database' => env('DB_DATABASE', 'My_db_name'),
        'username' => env('DB_USERNAME', 'db_usernamel'),
        'password' => env('DB_PASSWORD', 'db_password'),
        'unix_socket' => env('DB_SOCKET', '/Applications/MAMP/tmp/mysql/mysql.sock'),
        'charset' => 'utf8mb4',
        'collation' => 'utf8mb4_unicode_ci',
        'prefix' => '',
        'strict' => true,
        'engine' => null,
    ],

错误表明它正在尝试连接到本地主机

Illuminate\Database\QueryException thrown with message "SQLSTATE[HY000] [1045] Access denied for user 'db_username'@'localhost' (using password: YES) (SQL: select `users`.* from `followers` inner join `users` on `followers`.`follower_id` = `users`.`id` inner join `countries` on `users`.`country_id` = `countries`.`id` where (`followers`.`user_id` is null))"

预期的行为:应连接到远程数据库

/Applications/MAMP/Library/bin/mysql -u db_username -h 104.1XX.XX.XX -p

可以在终端中使用上述字符串进行连接

Able to make the connection using the above string in terminal

Laravel Framework 5.8.37

PHP 7.3.11 (cli)

Mamp Pro - 5.7

任何帮助将不胜感激.

推荐答案

根据您的错误,这不是Laravel项目的问题.它是您数据库的问题.您不能在部署数据库的服务器之外访问数据库.

As per your error its not the problem of Laravel project. Its the problem of your database. You cannot access the database outside of the server where it is deployed.

可能的问题如下:

1. Database user configured to access only for localhost and not outside

2. Proper database credentials

对于1,您可以使用以下

For 1 you can use the following

% -> stands for anywhere

基本上,下面将您授予用户USERNAME的所有访问权限,以便可以从世界任何地方访问

Basically with the below your giving all the access to the user USERNAME to access from anywhere in the world

GRANT ALL PRIVILEGES ON *.* TO 'USERNAME'@'%' IDENTIFIED BY 'PASSWORD' WITH GRANT OPTION; 
FLUSH PRIVILEGES;

在进行上述操作的同时,请确保执行以下操作

Along with the above make sure to do the following

更改文件/etc/mysql/mysql.conf.d/mysqld.conf 中的绑定地址

基本上它将是 127.0.0.1 ,或者您的服务器IP地址将其更改为 0.0.0.0

Basically it will be 127.0.0.1 or your server ip-address change it to 0.0.0.0

希望它对您有用.干杯.

Hope it works for you. Cheers.

这篇关于MAMP Pro OSX上的Laravel远程数据库连接问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆