At first I tried just connecting with PDO in PHP. However, I get access denied messages. I can use the exact same commands to connect to the command line interface, but php gives this error from PDO:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [1045] Access denied for user 'avt_root'#'localhost' (using password: YES)' in C:\inetpub\wwwroot\index.php:3 Stack trace: #0 C:\inetpub\wwwroot\index.php(3): PDO->__construct('mysql:host=loca...', 'avt_root', '[**]') #1 {main} thrown in C:\inetpub\wwwroot\index.php on line 3
$db = new PDO("mysql:host=localhost;dbname=AVT_TIME", "avt_root", "[**]");
So next I tried just connecting with mysql_connect to troubleshoot maybe having the PDO parameters incorrect:
$mysql = mysql_connect("localhost", "avt", "[**]");
However, even this gives me pretty much the same error:
Warning: mysql_connect(): Access denied for user 'avt'#'localhost' (using password: YES) in C:\inetpub\wwwroot\index.php on line 2
Server Configuration:
IIS7.0 with PHP running under fast_cgi and MySQL installed with correct extensions chosen in php.ini file.
Any and all help is appreciated, minus any comments regarding correct username and password, I have checked and triple checked for both the avt_root and avt accounts. The password for both is actually the same, and both can log in via the CLI over remote desktop.
localhost can be a little wonky in mysql-land. The standard mysql interface library, which mysql_*() functions use, internally redefine localhost to be a local unix-domain socket connection. This is purey for efficiency, as unix sockets do not have the overhead that TCP sockets do.
PDO, which is probably using mysqlnd, will not have that problem. localhost will mean 127.0.0.1 and it'll be trying to use a TCP socket.
Make sure that your avt account is set up as avt#127.0.0.1 to allow TCP connections.
I eventually gave up on this and completely reinstalled MySQL and am just going to use the root account, as we have high enough security that I don't have to worry too much about someone messing with an intranet only site.
Related
I am trying to connect to a remote Mysql server from my web server. I followed the following steps:
On the remote server:
1. “CREATE USER ’newremoteuser’#‘web-server_ip' IDENTIFIED BY 'remote_user_password’;”
2. “GRANT ALL PRIVILEGES ON *.* TO 'newremoteuser'#'web_server_ip’;”
3. “FLUSH PRIVILEGES;”
On the web server when I try to access using Mysql CLI, the connection is successful.
"mysql -u newremoteuser -h remote_server_ip -p"
However when I try to connect to remote server using PDO or Mysqli in PHP, I get the error
"FastCGI sent in stderr: "PHP message: PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[28000] [1045] Access denied for user 'newremoteuser'#'my-domain-name.com' (using password: YES)'
Below is the PDO code
$REMOTEPDO = new PDO("mysql:host=$remote_server_ip;port=3306;dbname=$remote_db", $newremoteuser, $remote_user_password);
$REMOTEPDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
I think it is denying access to 'newremoteuser'#'my-domain-name.com' as the remote user I added was 'newremoteuser'#'web-server_ip'. However, I can not find a solution to this. Can anyone please point me in the right direction?
Note: 'my-domain-name.com' is my website name hosted on my 'web_server_ip’ server.
Remote server is Ubuntu 18 and Web server is Ubuntu 14.
As you've pointed out, changing the host for that user might fix your problem since the connection denial seems to be because of a host mismatch. Try updating the host for your existing user from the IP address to the domain name:
UPDATE mysql.user SET Host='my-domain-name.com' WHERE User='username';
FLUSH PRIVILEGES;
If it still doesn't work, it might be worth updating the host to '%' instead and seeing if it then lets you connect.
I just went through this. I could connect with command line but not PDO. My webserver client wouldn't connect until I enabled httpd_can_network_connect_db on the client server's SELinux and rebooted.
sudo setsebool -P httpd_can_network_connect_db 1
I forgot the reboot and chased my tail a bit longer than necessary.
I've read many questions similar to this but none of the answers have been relevant to me. I'm trying to access a SQL server using PHP. Both the SQL server and PHP are running on my Windows 10 machine. Here is my PHP code (the username and password are arbitrary):
$connection = mysqli_connect('127.0.0.1', 'hmuuser', 'password');
This causes the following error:
PHP Warning: mysqli_connect(): (HY000/2002): No connection could be made because the target machine actively refused it.
Here is my connection using MSSMS (which is successful):
EDIT:
I was able to solve my problem using this link: http://blog.citrix24.com/configure-sql-express-to-accept-remote-connections/
Using this link I enable SQL Browser, and set a static port to connect to SQL server with. However, I'm presented with a new error:
PHP Warning: mysqli_connect(): MySQL server has gone away in C:\HMUAPI\Index.php on line 7
PHP Warning: mysqli_connect(): Error while reading greeting packet. PID=9920 in C:\HMUAPI\Index.php on line 7
PHP Warning: mysqli_connect(): (HY000/2006): MySQL server has gone away in C:\HMUAPI\Index.php on line 7
My code has been changed to the following to cause this error: $connection = mysqli_connect('127.0.0.1:1434', 'hmuuser', 'password');
Add a database name
$connection = mysqli_connect('127.0.0.1', 'hmuuser', 'password','dbname');
Also here is suggest - Actively refused it" means that the host sent a reset instead of an ack when you tried to connect. It is therefore not a problem in your code. Either there is a firewall blocking the connection or the process that is hosting the service is not listening on that port. This may be because it is not running at all or because it is listening on a different port.
I guess the problem is, that you use MySQLi to connect to a MSSQL server.
You should use the correct MSSQL extension instead.
Microsoft published their SQL-Server for PHP driver on GitHub: https://github.com/Microsoft/msphpsql
Or you use the older extension which is documented in the PHP manual: http://de2.php.net/manual/en/book.mssql.php
And at least you can set up ODBC.
One of them should resolve your problem.
I have an issue that is most probably a user rights issue.
I have a php script that connects using PDO to a sphinx db.
$sp = new PDO('mysql:host=127.0.0.1;port=9306;dname=', '', '');
When I run it from terminal using root account it works fine. But,
when I attempt to run it through browser as user apache I get the following error:
[Thu Mar 20 11:22:51 2014] [error] [client 98.12.26.274] PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2003] Can't connect to MySQL server on '127.0.0.1' (13)' in /var/www/html/surveys/test.php:3\nStack trace:\n#0 /var/www/html/surveys/test.php(3): PDO->__construct('mysql:host=127....', '', '')\n#1 {main}\n thrown in /var/www/html/surveys/test.php on line 3
There has to be something that is missing the propoer user rights but I have no clue what files I need to give rights to for this to work.
UPDATE:
I realized that selinux was blocking the port. How do I enable that port for apache using selinux?
Just use a socket instead of the IP address? See the manual for an example. This circumvents the network stack altogether.
Put something like
listen=/tmp/mysql_sphinx.sock
into the sphinx.cnf and put the same socket into the DNS of PDO like
$db = new PDO('mysql:dbname=testdb;unix_socket=/tmp/mysql_sphinx.sock');
This frees you from the need to make MySQL accessible over the network too. This is better taking security into account.
I have recently started exploring free hosting sites where they provide free mysql and php.
I have created a database and trying to connect to the database from php script. But while running the php. I am getting following error :
Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'a1696486_test '#'localhost' (using password: YES) in /home/a1696486/public_html/myphp/test1.php on line 2
Warning: mysql_select_db() [function.mysql-select-db]: Access denied for user 'a1696486'#'localhost' (using password: NO) in /home/a1696486/public_html/myphp/test1.php on line 3
Any idea whats the problem ?
Regards,
Shankar
I have this issue on our dedicated servers, and the solution for me is to provide the fully qualified domain name rather than 'localhost'. For exmaple, my connection is:
mysqli_connect('dedi81.jnb1.host-h.net', 'user', 'pass', 'db');
Where even though localhost is the same as dedi81.jnb1.host-h.net (MySQL server and web server on one machine) I - for some reason - cannot use 'localhost'.
Another issue may be that on the hosting company you're with, they have not granted to you the correct permissions, or that there is indeed an error with the username and / or password.
You can also try and substitute 'localhost' with the IP address of the MySQL machine.
Kind regards,
Simon
I have a system with a globally open mysql connection to the local server. In one of my files I am opening an additional connection to a remote machine.
Wieldly instead of trying to connect to that machine, I get an access denied message from my ISP (it seems to be trying to connect to the database on that machine).
I am trying to connect using:
$cust_conn = mysql_connect($host,'root','##password##');
I have tried subdomain.domain.com:3306, subdomain.domain.com and ip:3306 as the value for $host.
The wierd this is the response i get:
Warning: mysql_connect(): Access denied for user 'root'#'my.isp.com' (using password: YES) in /var/www/html/report/module/sql_view.php on line 19 Error: Could not connect to database:
Any ideas why this would happen? It seems like for some reason my script is attempting to connect to my ISPs server, instead of the one passed in $host.
The host given in the error message is the host it's trying to connect from, not to.
that hostname in the error (my.isp.com) is your client's host...remote root access is often disabled, or perhaps the pass/host combo is wrong
to add the creds:
http://dev.mysql.com/doc/refman/5.1/en/adding-users.html