I'm trying to connect to an AWS MySQL server from my VPS, but no matter what I try, I just get access denied, my user has privileges to connect from any host.
If I try to connect via PHP:
$db = new mysqli('mysite.cufncdsjslka.us-east-1.rds.amazonaws.com', 'my_user', 'my_pass', 'my_db');
Gives me: Warning: mysqli::mysqli(): (28000/1045): Access denied for user 'my_user'#'XXXX.myhost.com' (using password: YES) in /home/me/shopify/libraries/db.lib.php on line 4
If I try to connect via the MySQL CLI:
mysql -h mysite.cufncdsjslka.us-east-1.rds.amazonaws.com -umy_user -p
Gives me:
ERROR 1045 (28000): Access denied for user 'my_user'#'xxxx.myhost.com' (using password: YES)
This command works flawlessly on my PC, but not on my VPS.
I'm assuming it's some sort of security setting preventing MySQL from using external servers?
My VPS is running Debian squeeze with the LAMP components all from the standard Debian packages except for PHP which I manually updated to 5.4.
I'm posting this as a new question since most similar questions I've found on SO were a permissions issue (I've given my MySQL user priveliges to connect from any host) or a SELinux issue (which AFAIK doesn't apply to Debian)
OK.
I have seen this problem number of times for many different reasons. Since I cannot see your server or your logs so I am guessing from the information that there could be bind address issue.
In my.cnf check
bind-address=YOUR-SERVER-IP
change it to the the ipaddress of your mysql server for example 81.92.33.45
restart mysql after this. And if you are still unable to connect then let me know with the error info from log and I will look again.
Secondly make sure iptables are not causing problems.
iptables -A INPUT -i eth0 -p tcp --destination-port 3306 -j ACCEPT
Related
This is not about 'localhost'. Both the command line version of 'mysql' as well as a script I wrote in Perl (using perl-DBD-MySQL) can login, get to this database and work with it. Only PHP gives the permission denied error, and that error is not reported in any of the various log files. I even went as far as creating a simple test user in the database to avoid any issues with special characters in the password:
create user 'web'#'%' identified by 'Iamnotarobot';
and again the command line can login with this credential but PHP says permission denied.
I don't know what is throwing the error so I can't address it. I'm literally lost.
Relevant info:
RHEL 8 = 4.18.0
php 7.2.11
nginx 1.14.1
And here's the actual code that's failing:
<?php
$host="core";
$user="web";
$pass="Iamnotarobot";
$db="mydb";
$conn = new mysqli($host,$user,$pass,$db);
if( $conn->connect_errno ) {
exit($conn->connect_errno);
}
?>
It turned out to be an selinux issue. Here's how I fixed it:
setsebool -P httpd_can_network_connect_db 1
Now with setenforce back to '1', the page can connect to the database.
Check with php-mysql package installation.
If perl can connect remotely and php could not...the issue is with php-mysql installation only.
I am teaching myself how to code by watching Kevin Skoglund movies on Lynda. I am having troubles on one of the chapters in the series - creating a database. I am trying to log on to MySQL but is showing like this-
Rosss-MacBook-Air:~ rossnyland$ mysql -user -p
Enter password:
ERROR 1045 (28000): Access denied for user 'ser'#'localhost' (using password: YES)
Rosss-MacBook-Air:~ rossnyland$
The password is right because when I type a wrong password it will say (using password: NO)
What am I doing wrong? MySQL server is running, I'm using 5.7.20 version, using MAC OS x, and have tried to log on on mysqlworkbench, but message pops up saying this
Your connection attempt failed for user 'root' from your host to server at localhost:3306:
Access denied for user 'root'#'localhost' (using password: YES)
Please:
1 Check that mysql is running on server localhost
2 Check that mysql is running on port 3306 (note: 3306 is the default, but this can be changed)
3 Check the root has rights to connect to localhost from your address (mysql rights define what clients can connect to the server and from which machines)
4 Make sure you are both providing a password if needed and using the correct password for localhost connecting from the host address you're connecting from
Even I tried to delete it but no success! Please tell me what am I doing wrong or how to start over again...
The password could be right, but I doubt your user is ser.
When you use the command-line option -u, any text you put after it, is the username.
So if your username for mysql is mysql_user, you need:
$ mysql -umysql_user -p
or:
$ mysql -u mysql_user -p
or:
$ mysql --user=mysql_user --password
For the Command Line Tool error, you probably provided the wrong command. It should be:
$ mysql -u username -p
For the MySQL Workbench error, there are two possibilities:
You provided the wrong password for 'root'#'localhost'. Or the user 'root'#'localhost' didn't exist.
Your MySQL server didn't listen on the localhost interface. In other words, check the value of bind_ip in your my.cnf config file. You should provide the actual ip address by --host option in this case.
You can also check this answer I posted before, it shows you the full steps to solve this kind of problems.
This may be a duplicate question, however I searched internet for a while, and still couldn't find the solution.
I installed xampp on windows 7. The mysql is running on a random port. However, I can't access mysql from command line. I keep getting this error message:
ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost'
(10061 "Unknown error").
I enabled mysql for windows services as administrator, and opened the port that the mysql is using through windows firewall settings. But the problem is still not fixed, and I still can not see the port from http://canyouseeme.org/.
Open a command line with administrative privileges. Type the command below.
netstat -a -p tcp | findstr ":138"
Give it the port number that your sql is using instead of ":138" in the above example. Check if the output contains 0.0.0.0 as the IP or not. If it contains your local area network IP then use that IP to connect. Perhaps MySQL is not using all IPs to listen for connections.
maybe your mysql service is not running.
my solution:
open the run and type 'services.msc'
find the mysql count that you build(note:not the mysql, is the mysql count that you build yourself),then run this service.
Find your Path that you are install xampp server on and open CMD Write that
"C:\xampp\mysql\bin\mysqld"
click Enter and Close , reopen CMd and write
mysql -u root
video
I am facing a weird problem here
we have a server A where the app files are stored
and B server with database
Tried to connect via command prompt from server A to B using the command
mysql -h xx.xx.xx.xx -u root -p password - and it worked
NOw i tried to create a php script in server A to connect to server B
the command is
$this->db=new PDO('mysql:host=xx.xx.xx.xx;dbname=databasename','root','password');
Connection failed: SQLSTATE[HY000] [2003] Can't connect to MySQL
server on 'xx.xx.xx.xx' (13) Fatal error: Uncaught exception
'Exception' with message 'SQLSTATE[HY000] [2003] Can't connect to
MySQL server on 'xx.xx.xx.xx' (13)'
Unable to find a solution on this.
Can any help on this?
thank you
I got it working by running a command in the database server :)
setsebool httpd_can_network_connect_db=1
thanks for the replies yycdev
Try specifying the port in your connection string and ensure the database server is set to allow remote connections and the port is open on your firewall (both of these I suspect are already done as you are able to connect via the terminal but it never hurts to verify and check things).
Change your PDO connection and add the port=3306 or if you're using MAMP use port 8889
$this->db=new PDO('mysql:host=xx.xx.xx.xx;port=3306;dbname=databasename','root','password');
Another thing to check is if – SELinux is blocking network connections. Login as root and run
setsebool -P httpd_can_network_connect=1
I don't know much about that, but try to place the port in back of the script:
$this->db=new PDO('mysql:host=xx.xx.xx.xx;dbname=databasename','root','password',3306);
I am trying to set up the MAMP development environment in MAC OS X Yosemite(10.10.2).
I am following this tutorial.
But problems happen when I try to set MySQL root password using command /usr/local/mysql/bin/mysqladmin -u root password 'yourpasswordhere'. I get a error message :
"/usr/local/mysql/bin/mysqladmin: connect to server at 'localhost'
failed error: 'Access denied for user 'root'#'localhost'
(using password: NO)'".
MAMP PRO has a great UI ...
... as for MAMP without the PRO, I don't remember. But I think it required adding MAMP's SQL to your PATH.
if u use mamp then why to set the password from the trmnl ,u can easily set it up through mamp it self