【问题标题】:Php artisan can't make migratephp工匠无法迁移
【发布时间】:2020-04-01 09:01:26
【问题描述】:

您好,我在使用 php artisan migrate 的 vps 服务器上进行迁移时遇到问题。 我已经安装了 apache2 和 mysql。 我可以通过mysql -u root -p 使用密码“pass#$”连接到我的数据库。 这是我的环境。

APP_NAME=Laravel
APP_ENV=local
APP_KEY=**
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=mysql
DB_USERNAME=root
DB_PASSWORD=pass#$

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

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

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

我的数据库中有这些信息:


+--------------------+
| Database           |
+--------------------+
| information_schema |
| laravel            |
| mysql              |
| performance_schema |
| sys                |
+--------------------+

以及mysql中的这个表信息


+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| columns_priv              |
| db                        |
| engine_cost               |
| event                     |
| func                      |
| general_log               |
| gtid_executed             |
| help_category             |
| help_keyword              |
| help_relation             |
| help_topic                |
| innodb_index_stats        |
| innodb_table_stats        |
| ndb_binlog_index          |
| plugin                    |
| proc                      |
| procs_priv                |
| proxies_priv              |
| server_cost               |
| servers                   |
| slave_master_info         |
| slave_relay_log_info      |
| slave_worker_info         |
| slow_log                  |
| tables_priv               |
| time_zone                 |
| time_zone_leap_second     |
| time_zone_name            |
| time_zone_transition      |
| time_zone_transition_type |
| user                      |
+---------------------------+

更重要的是,我首先在我的电脑上创建了我的项目,现在我只能从我的 github 存储库中获取它。 当我转到我的网站 ip 时,我可以看到我所有的网站和视图。

我尝试将 .env 文件 127.0.0.1 更改为 localhost,尝试通过 php artisan config:clearphp artisan cache:clear 清除配置,但它仍然不起作用。

编辑:我忘了

php artisan migrate

   Illuminate\Database\QueryException  : SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) (SQL: select * from information_schema.tables where table_schema = mysql and table_name = migrations and table_type = 'BASE TABLE')

  at /home/projects/test/ArduinoWeather/vendor/laravel/framework/src/Illuminate/Database/Connection.php:669
    665|         // If an exception occurs when attempting to run a query, we'll format the error
    666|         // message to include the bindings with SQL, which will make this exception a
    667|         // lot more helpful to the developer instead of just the database's errors.
    668|         catch (Exception $e) {
  > 669|             throw new QueryException(
    670|                 $query, $this->prepareBindings($bindings), $e
    671|             );
    672|         }
    673|

  Exception trace:

  1   PDOException::("SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES)")
      /home/projects/test/ArduinoWeather/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70

  2   PDO::__construct("mysql:host=localhost;port=3306;dbname=mysql", "root", "pass", [])
      /home/projects/test/ArduinoWeather/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70

  Please use the argument -v to see more details.

【问题讨论】:

  • 从工匠输出中得到的错误是什么?
  • 您是否尝试过将密码放在引号中? DB_PASSWORD="pass#$" 不确定 DotEnv/Laravel 处理密码中那些“特殊字符”的能力如何
  • 哦,我没看到这个,谢谢,现在工作

标签: php mysql laravel server laravel-artisan


【解决方案1】:

确保您的 mysql 在端口 3306 上运行,并且您的用户名和密码正常。 然后转到您的项目文件夹并

config/database.php

改变这些:

'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),

而不是使用 .env 使用静态内联用户名和密码,例如:

'usename' => 'root',
'password' => 'your password'

看看它是否有效。

【讨论】:

    猜你喜欢
    • 2018-12-02
    • 1970-01-01
    • 2023-03-10
    • 2017-06-20
    • 2016-06-16
    • 2020-01-22
    • 1970-01-01
    • 2017-11-29
    • 2021-06-15
    相关资源
    最近更新 更多