简体   繁体   中英

MYSQL Connection not allowing IP Address

When I run the following from my webserver it runs fine:

$ip = "localhost";
$uname = user
$pw = user password
$tb = table name


$dbconn = mysqli_connect($ip, $uname, $pw, $tb) or die("Couldn't connect");

However, when I make the following change, I get the "Couldn't connect" error:

$ip = "X.X.X.X";

Where X is the Public IP of my web server. Even when I change it to:

$ip = "127.0.0.1";

I get the couldn't connect error.

Can anybody think of a reason this would be refusing the connection?

Thanks

EDIT: I have looked on the server logs and get the following (when I do 127.0.0.1):

[26-Nov-2015 23:51:38 Europe/Moscow] PHP Warning:  mysqli_connect(): (28000/1045): Access denied for user '*USERNAME*'@'127.0.0.1' (using password: YES) in /filepath/

Where ' USERNAME ' is my db username in the correct format, (cpname_dbuser)

If you are trying to access Mysql from remote location then you have to enable Remote Mysql or Whiltelist your ip

Use mysqli_connect_error() to return last connection error

You need to grant privileges from the IP address of your webserver, open port 3306 on the firewall to allow the IP you are connecting from access to the database and you will need to bind MySQL to the IP address you are connecting to. You can do this in the MySQL configuration file (search for bind-address).

To grant privileges you can log in as MySQL root and type the following...

grant all privileges on <database>.* to <username>@<ip address> identified by 'yourpassword'

Where ip address is the address of the machine you are accessing the database from.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM