MySQL SQLSTATE[HY000] [1045] 用户 'root'@'127.0.0.1' 的访问被拒绝(使用密码:NO)SYMFONY2
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21730863/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SQLSTATE[HY000] [1045] Access denied for user 'root'@'127.0.0.1' (using password: NO) SYMFONY2
提问by Seif Sayed
So I'be been working on a symfony2 project and it was all good, then i wanted to host it on godaddy but now I get this error. I don't understand it neither do I know how to fix it. thanks so much.
所以我一直在做一个 symfony2 项目,一切都很好,然后我想把它托管在 Godaddy 上,但现在我遇到了这个错误。我不明白它也不知道如何解决它。非常感谢。
SQLSTATE[HY000] [1045] Access denied for user 'root'@'127.0.0.1' (using password: NO)
SQLSTATE[HY000] [1045] 用户 'root'@'127.0.0.1' 的访问被拒绝(使用密码:NO)
This is my paramaters.ymlfile
这是我的paramaters.yml文件
# This file is auto-generated during the composer install
parameters:
database_driver: pdo_mysql
database_host: 127.0.0.1
database_port: null
database_name: symfony
database_user: root
database_password:
mailer_transport: smtp
mailer_host: 127.0.0.1
mailer_user: null
mailer_password: null
locale: en
secret: 14bcde878eda1c3f56a59b62b13e820b7f94563d
This is my config.ymlfile
这是我的config.yml文件
imports:
- { resource: parameters.yml }
- { resource: security.yml }
framework:
#esi: ~
#translator: { fallback: "%locale%" }
translator: ~
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
templating:
engines: ['twig']
#assets_version: SomeVersionScheme
default_locale: "%locale%"
trusted_hosts: ~
trusted_proxies: ~
session:
# handler_id set to null will use default session handler from php.ini
handler_id: ~
fragments: ~
http_method_override: true
# Twig Configuration
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
# Assetic Configuration
assetic:
debug: "%kernel.debug%"
use_controller: false
bundles: [ ]
#java: /usr/bin/java
filters:
cssrewrite: ~
#closure:
# jar: "%kernel.root_dir%/Resources/java/compiler.jar"
#yui_css:
# jar: "%kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar"
# Doctrine Configuration
doctrine:
dbal:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
# if using pdo_sqlite as your database driver, add the path in parameters.yml
# e.g. database_path: "%kernel.root_dir%/data/data.db3"
# path: "%database_path%"
orm:
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: true
# Swiftmailer Configuration
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
fos_user:
db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel'
firewall_name: main
user_class: CurrencyConverter\ConverterBundle\Entity\User1
sensio_framework_extra:
view:
annotations: false
fos_rest:
param_fetcher_listener: true
body_listener: true
format_listener: true
view:
view_response_listener: 'force'
I got the password and username now I get:
我现在得到了密码和用户名:
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known
SQLSTATE[HY000] [2002] php_network_getaddresses:getaddrinfo 失败:名称或服务未知
回答by kratos
Your database_user
and database_password
values need to be set in the parameters.yml
file. You can get those settings in the GoDaddy new account setup email that gets provided to you.
您的database_user
和database_password
值需要在parameters.yml
文件中设置。您可以在提供给您的 GoDaddy 新帐户设置电子邮件中获取这些设置。
回答by Ahmed Siouani
The error message you got is clear enough,
你得到的错误信息很清楚,
SQLSTATE[HY000] [1045] Access deniedfor user 'root'@'127.0.0.1' (using password: NO)
SQLSTATE[HY000] [1045]用户 'root'@'127.0.0.1' 的 访问被拒绝(使用密码:NO)
You need to set the right database_user
& database_password
in the parameters.yml
used in your host. Check your accont configuration to get the right access parameters.
您需要设置权database_user
和database_password
在parameters.yml
主机中的使用。检查您的帐户配置以获得正确的访问参数。
回答by Ahmed Rachdi
It depends on your hosting provider then . Sometimes when you have a shared server hosting the username is not root it could be {YOURGODADDYACCOUNT_root} or somthing. check your cpanel or plesk administration to get the right credentials.
这取决于您的托管服务提供商。有时,当您有一个共享服务器托管用户名不是 root 时,它可能是 {YOURGODADDYACCOUNT_root} 或其他东西。检查您的 cpanel 或 plesk 管理以获取正确的凭据。
回答by Nemus
As error message said. You need to provide some password. In my case, I just added 'root'
for the password in parameters.yml
file:
正如错误消息所说。您需要提供一些密码。就我而言,我只是'root'
在parameters.yml
文件中添加了密码:
...
database_user: root
database_password: root
...
回答by Woleks
I changed database_host parameter in app/config/parameters.yml to 0.0.0.0 and this error disappeared.
我将 app/config/parameters.yml 中的 database_host 参数更改为 0.0.0.0,此错误消失了。