mysql连接被拒绝_MySQL数据库连接被拒绝

bd96500e110b49cbb3cd949968f18be7.png

I am trying to get my Symfony 3 app running in production mode on an Amazon EC2 instance.

I am have the code in the correct place, and then I try to setup any dependencies with composer by running

export SYMFONY_ENV=prod

composer install --no-dev --optimize-autoloader

but get the error

> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installAssets

[Doctrine\DBAL\Exception\ConnectionException]

An exception occured in driverL SQLSTATE[HY000] [1044] Access denied for user 'my-user'@'127.0.0.1' to database 'my_database'

This error is then passed down to [Doctrine\DBAL\Driver\PDOException] and [PDOException] before the script terminates.

This is then followed by the message

[RuntimeException]

An error occured when executing the "'assets:install --symlink --rela'\''web'\'''" command:

which is then followed by the same errors as at the beginning.

My parameters.yml file is

parameters:

database_host: 127.0.0.1

database_port: 3306

database_name: my_database

database_user: my-user

database_password: mypassword

server_version: 5.6

mailer_transport: smtp

mailer_host: 127.0.0.1

mailer_user: null

mailer_password: null

secret: Mysecret

registration_permitted: true

registration_limit: 3

and the user my-user has all permissions on the database my_database except GRANT.

I have been trying to solve this for a few hours to no avail, other solutions I came across involved misspelt usernames/passwords/databases (triple-checked) or needed the server version adding (which hasn't made a difference).

Additional Info

Running mysql -u my-user -p prompts for the password and then allows me to log in.

Running mysql -u my-user -p -D my_database prompts for the password and then returns ERROR 1044 (42000): Access denied for user 'my-user'@'localhost' to database 'my_database'.

Logging into mysql as root and running SHOW GRANTS FOR 'my-user'; returns ERROR 1141 (42000): There is no such grant defined for user 'my-user' on host '%'.

Logging into mysql as root and running SHOW GRANTS FOR 'my-user'@'localhost'; returns GRANT USAGE ON *.* TO 'my-user'@'localhost' IDENTIFIED BY PASSWORD hashedPassword.

Additional Info 2

After deleting my-user ('my-user'@'localhost' and 'my-user'@'127.0.0.1') and then recreating them using GRANT ALL PRIVILEGES ON my_database.* TO 'my-user'@'localhost' IDENTIFIED BY 'password'; and also GRANT ALL PRIVILEGES ON my_database.* TO 'my-user'@'127.0.0.1' IDENTIFIED BY 'password'; and then FLUSH PRIVILEGES; The output of SHOW GRANTS FOR 'my-user'@'localhost' is then

GRANT USAGE ON *.* TO 'my-user'@'localhost' IDENTIFIED BY PASSWORD 'passwordHash'

GRANT ALL PRIVILEGES ON 'my_database' TO 'my-user'@'localhost'

and similar output for 'my-user'@'127.0.0.1'.

But this is still giving me the same errors as before, any more ideas?

解决方案

As discussed in comments you did not have any privilege on the database.

So running this fixes your problem:

GRANT ALL PRIVILEGES ON my_database.* TO 'my-user'@'localhost'

About your doubt why you had to change it to localhost in your params because that's what you're telling mysql

Imagine you want to restrict database access to only a specific ip in your network you could run

GRANT ALL PRIVILEGES ON my_database.* TO 'my-user'@'192.168.1.10'

So replace 192.168.1.10 with 127.0.0.1 and you can use 127.0.0.1 in your parameters

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值