0

I am trying to connect to a remote Mysql server using ssl from my PHP Yii application. I am able to establish the connection and am able to query the DB when doing so from yii console using below command

./yii script.

However, the exact same script doesn't work when I am trying to run it on the server using below command

php yii serve --port = 8090

I get the below error :

yii\base\ErrorException: mysqli_real_connect(): (HY000/1045): Access denied for user 'userName'@'IP' (using password: YES).

I have verified the php setting by printing phpInfo() from both the places, and it is same. So I am unable to understand what could be the issue here. I would highly appreciate any help/pointers to resolve this.

specification : php 7.1.28, Yii2

Update 1

The application in question has its own specific DB, which I am connecting to using PDO (it is fine). Then there is this remote Mysql server, which I am not able to connect using PDO because of SSL peer match issue. I have tried this resolve by doing

PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT => False

but the constant is not present in the PDO. However, if I do

php -r ‘var_dump(PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT);’

i get int(1014) as the output. Not sure why my appilcation is not picking the constant.

Lelio Faieta
  • 6,457
  • 7
  • 40
  • 74
viks1010
  • 101
  • 8
  • Do not put spaces for your port argument: `--port=8090`. Then you have to grant access to the user and IP you are using to connect. – Nic3500 Jun 28 '19 at 18:45
  • I am able to connect for the same user via console, so it is not exactly a permission issue. I am assuming that there is some issue because of Yii configs, but I am not able to figure out what. – viks1010 Jun 29 '19 at 05:22
  • You did not show any Yii configurations in the question. – Nic3500 Jun 29 '19 at 05:28
  • May be I did not phrase my question properly, please read the update. – viks1010 Jun 29 '19 at 09:45
  • 1
    Possible duplicate of [PHP - SSL certificate error: unable to get local issuer certificate](https://stackoverflow.com/questions/28858351/php-ssl-certificate-error-unable-to-get-local-issuer-certificate) – Dharman Jun 29 '19 at 15:53

1 Answers1

0

Open new terminal

sudo /etc/init.d/mysql stop ... MySQL Community Server 5.7.8-rc is stopped

sudo mysqld_safe --skip-grant-tables & this will skipp all grant level privileges and start the mysql in safe mode Sometimes the process got stucked just because of

grep: write error: Broken pipe 180102 11:32:28 mysqld_safe Logging to '/var/log/mysql/error.log'.

Simply press Ctrl+Z or Ctrl+C to interrupt and exit process

mysql -u root

Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.8-rc MySQL Community Server (GPL)

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use mysql;

Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A

Database changed

mysql> update user set authentication_string=password('password') where user='root'; Query OK, 4 rows affected, 1 warning (0.03 sec) Rows matched: 4 Changed: 4 Warnings: 1

mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)

mysql> quit Bye

sudo /etc/init.d/mysql stop

..180102 11:37:12 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended . * MySQL Community Server 5.7.8-rc is stopped arif@ubuntu:~$ sudo /etc/init.d/mysql start .. * MySQL Community Server 5.7.8-rc is started

mysql -u root -p

Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.8-rc MySQL Community Server (GPL)

after mysql 5.7+ version the column password replaced by name authentication_string from the mysql.user table.