如何使用Laravel Framework 5.1在端口3308上连接到MySQL数据库?

问题描述:

我正在尝试第一次使用laravel.我选择位于config目录中的database.php文件,然后更新mysql配置.

I am trying to use laravel for the first time. I opned the database.php file located in the config directory and then update the mysql config.

但是每次我尝试执行此命令时 php artisan migration:install

but every time I try to do this command php artisan migrate:install

我明白了 [PDOException] SQLSTATE [HY000] [2002]无法建立连接,因为目标机 ne主动拒绝了.

I get this [PDOException] SQLSTATE[HY000] [2002] No connection could be made because the target machi ne actively refused it.

我必须让laravel以某种方式连接到另一个端口.

I have to let laravel to connect to a different port somehow.

我尝试了以下方法,但均无效果.

I have tried the following and none worked.

    'mysql' => [
        'driver'    => 'mysql',
        'host'      => env('DB_HOST', '10.15.1.5'),
        'port'      => '3308',
        'database'  => env('DB_DATABASE', 'mydb_dev'),
        'username'  => env('DB_USERNAME', 'user'),
        'password'  => env('DB_PASSWORD', 'pass'),
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix'    => '',
        'strict'    => false,
    ],

还有这个

    'mysql' => [
        'driver'    => 'mysql',
        'host'      => env('DB_HOST', '10.15.1.5:3308'),
        'database'  => env('DB_DATABASE', 'mydb_dev'),
        'username'  => env('DB_USERNAME', 'user'),
        'password'  => env('DB_PASSWORD', 'pass'),
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix'    => '',
        'strict'    => false,
    ],

还有这个

    'mysql' => [
        'driver'    => 'mysql',
        'host'      => env('DB_HOST', '10.15.1.5'),
        'port'      => env('DB_PORT', '3308'),
        'database'  => env('DB_DATABASE', 'mydb_dev'),
        'username'  => env('DB_USERNAME', 'user'),
        'password'  => env('DB_PASSWORD', 'pass'),
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix'    => '',
        'strict'    => false,
    ],

最后,我尝试了

    'mysql' => [
        'driver'    => 'mysql',
        'host'      => '10.15.1.5:3308',
        'database'  => env('DB_DATABASE', 'mydb_dev'),
        'username'  => env('DB_USERNAME', 'user'),
        'password'  => env('DB_PASSWORD', 'pass'),
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix'    => '',
        'strict'    => false,
    ],

这给了我一个不同的错误

this gives me a different error

Access denied for user 'homestead'@'10.xxxxxx' (using password: YES)

我不确定用户homestead来自哪里.

I am not sure where is the user homestead is coming from.

如何告诉laravel在端口3308上连接到mysql?

How can I tell laravel to connect to mysql on port 3308?

我发现了问题所在. .env文件需要使用正确的信息进行更新

I figured out the issue. the file .env needs to be updated with the correct information