duancoubeng5909 2019-07-01 07:56
浏览 207

Laravel msql配置%db_name%缓存问题

I'm trying to configure msql db with laravel and I have a strange problem. After searching on line I'm still not getting my migration done.

in my .env I have

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT='%db_port%'
DB_DATABASE='forge'
DB_USERNAME='root'
DB_PASSWORD='password'

so after changing .env I did php artisan cache:clear then php artisan config:cache, after that running php artisan migrate I got

   Illuminate\Database\QueryException  : SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known (SQL: select * from information_schema.tables where table_schema = %db_name% and table_name = migrations)

  at /Users/p/Documents/Project/hub-family-server/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   Doctrine\DBAL\Driver\PDOException::("SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known")
      /Users/p/Documents/Project/hub-family-server/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:31

  2   PDOException::("PDO::__construct(): php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known")
      /Users/p/Documents/Project/hub-family-server/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:27

  Please use the argument -v to see more details.

Now interacting with the application with php artisan tinker and checking

Psy Shell v0.9.9 (PHP 7.2.19 — cli) by Justin Hileman
>>> env('DB_USERNAME')
=> null
>>> config('database.connections.mysql.database')
=> "%db_name%"
>>> env('DB_HOST')
=> null
>>> env('DB_USERNAME')
=> null
>>> 

So I'm not sure anymore what is happening, also I did update the dbal with composer require doctrine/dbal but that did not do anything. Can someone please help me understand what is happening thanks.

  • 写回答

4条回答 默认 最新

  • dousikuai5417 2019-07-01 08:00
    关注

    i think the problem is about the DB_PORT , it should be 3306, or whatever according to server settings. change the DB_PORT and if all other data is correct , it should work.

    评论

报告相同问题?

悬赏问题

  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了