propel:database:create access denied for user 'user'#'localhost' - php

For my Symfony2 project, I'm using Propel with MySQL.
When I deployed it on a server and ran:
php app/console propel:database:create --env=prod
I got this error:
[Propel] Exception caught
Unable to open PDO connection [wrapped: SQLSTATE[28000] [1045] Access denied for user 'user'#'localhost' (using password: YES)]
Which is really weird because when I run MySQL CLI with exactly the same host, user and password it works fine.
$ mysql -h localhost -u user -p
Propel-bundle: 1.2.13
What's going on?

Try these steps
Configure config/databases.yml with the working username and password. Ensure you are using the correct password and port here
propel:
class: sfPropelDatabase
param:
classname: PropelPDO
dsn: 'mysql:dbname=your-database-name;host=localhost'
port : 3306
username: user
password : your-password
encoding: utf8
persistent: true
pooling: true
Disable SELnux: If SELinux is enabled which can block the connection. Try to disable that, although not the optimal for those that like of security on their systems

Related

Database issue after creating a new Droplet using backup on Digitalocean

I am getting this error. In codeigniter 2.1.3
Connection failed: Access denied for user 'root'#'localhost' (using password: YES)
I have tried hard.
I have done restart Apache and MySQL.
Tried with adding ip as hostname.
Have edited my.cnf file.

Mysql cannot login from user account

From root user, I can execute this command without any problems:
[root#freebsd ~/var/html/www]$ bin/console d:run-sql 'SELECT * from user';
From www user, I cannot execute this command:
[www#freebsd ~/var/html/www]$ bin/console d:run-sql 'SELECT * from user';
because I am getting the following error:
An exception occurred in driver: SQLSTATE[HY000] [2002] Permission denied
Both users are using the same config file:
parameters:
database_driver: "pdo_mysql"
database_url: "mysql://dbuser:dbuserpass#127.0.0.1:3306/dbname"
I am using MariaDB 10.4 which is running on Freebsd with PHP(Symfony project)
Authentication problems comes with an access denied message.
A permission denied error means that you authentication happened but the resource you're trying to access was denied. Probably the dbname database.
You need to grant at least a "select" permission to this user with root or another administrator user:
GRANT SELECT ON dbname.* TO dbuser#127.0.0.1;
Pay attention because with mysql client if we don't specify a host or specify it like localhost instead of 127.0.0.1, the client tries to connect trought unix socket.
You can overcome this with --protocol tcp or using a IP address.

MySQL8 connection with php7.3 and Symfony 5 does not work

I have a connection problem with a mysql8 database, php7.3 and Symfony 5. The user and the password are correct !
The connection to MySQL8 database must be done from an SSH tunnel
The SSH tunnel is working :
ssh -p [remote_machine_port] -N -L [mysql_tunnel_port]: 127.0.0.1: 3306 -i / [directory] / private_key [username] # [remote_machine_ip]
MySQL access configuration:
GRANT ALL PRIVILEGES ON 'databasename'.* TO '[user]'#'%' WITH GRANT OPTION;
Doctrine configuration :
DATABASE_URL='mysql://[user]:[password]#127.0.0.1:[port_tunnel_mysql]/[databasename]'
An exception occurred in driver: SQLSTATE [HY000] [1130] Host '127.0.0.1' is not allowed to connect to this MySQL server
I have the same problem with heidiSQL and on the VM
I tried with the Ip of the VM instead of 127.0.0.1
ssh -p [port_machine_distant] -N -L [port_tunnel_mysql]:[ip_machine_vm]:3306 -i /[directory]/private_key [username]#[ip_machine_distant]
Doctrine configuration
DATABASE_URL='mysql://[user]:[password]#[ip_machine_vm]:[port_tunnel_mysql]/[databasename]'
An exception occurred in driver: SQLSTATE [HY000] [2002] Connection refused
However, this setting works with heidiSQL but not with the Symfony application !
Did I forget a setting on the VM or Mysql ?
127.0.0.1 connection issue :
We have created the '[user]'#'127.0.0.1' rights.
In MySQL, 127.0.0.1 uses the network and localhost uses the socket.
The message "The server requested authentication method unknown to the client [caching_sha2_password]" was caused because the setting 'default-authentication-plugin=mysql_native_password' was created after the creation of the rights.
We regenerated the rights, and now everything is working fine.

Mysql Database connection denied

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

How to resolve this MySQL error in Mac OS X Sierra?

I have been trying to reset the root password for MySQL on my Mac OS X Sierra and I cannot believe I can't find documentation for this anywhere that can resolve my problem.
The first error I got when I tried to access my database is this:
Error: Access denied for user 'root'#'localhost' (using password: NO)
I figured I would completely remove MySQL and install it again with brew but when I tried with mysql_secure_installation and I get this:
Securing the MySQL server deployment.
Enter password for user root:
Error: Access denied for user 'root'#'localhost' (using password: NO)
Also when I try to run:
mysql.server stop
I get this error:
ERROR! MySQL server PID file could not be found!
On mac, I think you have to use root as a password.
open mysqld_safe
mysql.server stop
mysqld_safe --skip-grant-tables
open a new terminal
mysql -uroot -p
use mysql;
update user set password=PASSWORD('123456') where user="root";
flush privileges;
quit;
close mysqld_safe terminal
restart mysql
mysql.server start
mysql -uroot -p
123456

Categories