【发布时间】:2019-09-16 03:54:05
【问题描述】:
我正在尝试使用 phalcon 创建模型。但是当我输入phalcon model polls 时,我得到一个错误ERROR: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES)。
我可以使用mysql -p 进入mysql。所以我尝试创建新用户并授予他所有权限,但没有帮助。我也可以使用 root 和密码登录 phpmyadmin。我也尝试在配置文件中将端口指定为 3306,但仍然没有。
我的配置文件:
defined('BASE_PATH') || define('BASE_PATH', getenv('BASE_PATH') ?: realpath(dirname(__FILE__) . '/../..'));
defined('APP_PATH') || define('APP_PATH', BASE_PATH . '/app');
return new \Phalcon\Config([
'database' => [
'adapter' => 'Mysql',
'host' => 'localhost',
'port' => 3306,
'username' => 'root',
'password' => '$Pass1234 ',
'dbname' => 'poll_db',
'charset' => 'utf8',
],
'application' => [
'appDir' => APP_PATH . '/',
'controllersDir' => APP_PATH . '/controllers/',
'modelsDir' => APP_PATH . '/models/',
'migrationsDir' => APP_PATH . '/migrations/',
'viewsDir' => APP_PATH . '/views/',
'pluginsDir' => APP_PATH . '/plugins/',
'libraryDir' => APP_PATH . '/library/',
'cacheDir' => BASE_PATH . '/cache/',
// This allows the baseUri to be understand project paths that are not in the root directory
// of the webpspace. This will break if the public/index.php entry point is moved or
// possibly if the web server rewrite rules are changed. This can also be set to a static path.
'baseUri' => preg_replace('/public([\/\\\\])index.php$/', '', $_SERVER["PHP_SELF"]),
]
]);
P.S 我做了所有关于通过mysql -u root -p授予进入mysql的权限的操作
P.P.S 我也做了FLUSH PRIVILEGES 然后重新启动了 mysql,但没有。感谢您以后的帮助。
UPD:我还尝试在 laravel 中创建项目,并进行了迁移,一切正常。我也使用了 root + 密码。
已解决:我不知道为什么,但我决定创建新项目,即使使用 'root'@'localhost' 也一切正常。似乎第一个项目出了点问题。尽管如此,还是感谢所有参与帮助的人。
P.S 我将EternHour's 的答案标记为解决方案,仅供将来可能遇到相同错误的人使用。
【问题讨论】:
-
如何在 DI 容器中注册你的数据库服务?
-
@NikolaosDimopoulos 我没有做任何事情,比如在 DI 容器中注册服务,我是 phalcon 的新手。
-
你在 Laravel 中是用 socket 连接 MySQL 服务器还是用 tcp 连接?
-
@KoalaYeung 我不确定,我使用composer create-project创建项目,然后修改.env文件
-
你的 Laravel 的
.env文件中有DB_PORT吗?