the script of connection =
<?
$server = "192.168.0.167";
$username = "root";
$password = "";
$database = "dbbook";
mysql_connect($server,$username,$password) or die("Koneksi gagal");
mysql_select_db($database) or die("Database tidak bisa dibuka");
?>
and i had add this script on my.cnf file after [mysqld] =
bind-address=192.168.0.167
but it didnt work with the following caption
mycomputer.mshome.net is not allowed to connect to this Mysql server
Please help me.How to remote database mysql XAMPP from another computer ?
You will have to create a new user in MySQL that is allowed to connect from a remote host.
By default, root can only connect from localhost.
You could try running the following commands from the MySQL server (make sure to substitute 192.168.0.99 with the IP or hostname of the PC that will be connecting) In your case, try 'php'#'mycomputer.mshome.net' for the user:
CREATE USER 'php'#'192.168.0.99' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON dbbook.* TO 'php'#'192.168.0.99';
It is possible to specify a wildcard host ('php'#'%'), but then if anyone got your MySQL password they could connect to the DB. You could also wildcard your subnet ('php'#'192.168.0.%') which is a little safer.
Related
I was given an username, password, database name and an url for accessing the phpmyadmin console for a specific application. Now I want to connect to the database, which ip address I also know.
I tried running the following php snippet (from my local installation of xampp), which gave me an error, saying:
"Warning: mysql_connect(): Access denied for user 'xxxxxxx'#'localhost' "
<html>
<head>
</head>
<body>
<?php
$username = "given_username";
$password = "given_password";
$db_name = "given_database_name";
$hostname = "xxxxx:3306"; //remote address
//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
echo "Connected to MySQL<br>";
?>
</body>
</html>
My question is: Are the password and username for mysql and phpmyadmin the same, and, am I running this correctly?
Looking at your question, I assume the php code and the MySQL server run on different machines. In that case, you have to create a remote user in your MySQL server.
Login to your MySQL console on the MySQL server:
mysql -u root -p
Grant access to remote user
mysql> GRANT ALL ON given_database_name.* TO given_username#'<ip address of the php server>' IDENTIFIED BY 'given_password';
Now you should be able to connect MySQL from remote machine. If your MySQL server is behind a firewall, make sure you open incoming port of MySQL (default is 3306).
When I try to connect to a website database using the code:
$server = "domain";
$login = "username";
$password = "password";
$database = "databasename";
$port = 3307;
$con = mysqli_connect($server, $login, $password, $database, $port);
and have all warnings and errors enabled I get a message saying
Warning: mysqli_connect(): (HY000/2003): Can't connect to MySQL server on 'domain' (111) in 'path'
however when I change $server to localhost it works fine.
If it is blocking me through php unless I use localhost does anyone know why the HeidiSQL or MySQL Administrator clients can connect using the domain?
What I understand from your problem statement, you are unable to connect to MySQL server using domain or IP address.
To resolve it, first you need to give database access permission to user. Checkout below sql which will do work for you.
GRANT ALL PRIVILEGES ON `databasename`.* TO 'username'#'domain' IDENTIFIED BY 'password' WITH GRANT OPTION;
Once permissions are granted to user check your MySQL configuration settings. Edit your MySQL confifuration file my.cnf and set nbelow mentioned settings.
Set the bind-address to 0.0.0.0 or comment it out:
bind-address = 0.0.0.0
OR
# bind-address = 127.0.0.1
Here is my code:
<?php
require_once('config.php');
$link = mysqli_connect($db_host, $db_user, $db_pass, $db_name) or die ('Your DB connection is misconfigured. Enter the correct values and try again.');
?>
I have stored my host, username, password and database name in the separate file config.php. I know that the information is correct because I can connect to my database via putty, but I keep getting the error:
Warning: mysqli_connect(): (HY000/1045): Access denied for user
'blank'#'T9AF3.WPA.blank.Ca' (using password: YES) in
C:\xampp\htdocs\temp2\index.php on line 3 Your DB connection is
misconfigured. Enter the correct values and try again.
Note: 'blank' is there to protect my identity and is not a typing error.
Edit: I only used putty to test that my login information was correct. Putty has very little to do with my actual question.
Edit2:
<?php
$db_host = 'host';
$db_user = 'user';
$db_pass = 'pass';
$db_name = 'dbname';
?>
These are filers.
if you can login from putty, by that i think you mean localhost, and you can't from php file, which is i think trying to connect remotely, the problem most probably lies on your user not defined for your servers ip. your server, which you are trying to connect from is 'T9AF3.WPA.blank.Ca'
in mysql a username has a password and a location and mysql uses both to authenticate the user. you can have permission to connect locally but not remotely i.e. from another server. check with your system admin to make sure you have proper access defined from 'T9AF3.WPA.blank.Ca'.
Or you have not specified an IP Address for the server to listen to. It may only be listening on localhost of your server, instead of allowing remote connections. Check your mysql configuration and which IP address it is listening on.
Your mysql user must have proper rights on the database you are using
I want to ask about how to connect my localhost application (C:xampp/htdocs/myproject) to database at my server host (www.someweb.somedomain)?
Am I possible to do that? If it is, how to connect it at my php config? Right now my config (server.php) is:
<?php
$host = "my web IP public:3306";
$user = "root";
$pass = "";
$db = "dispatcherDB";
$conn = mysql_connect($host, $user, $pass) or die ("Cant connect to mySQL");
mysql_select_db($db);
?>
what I got:
Warning: mysql_connect(): No connection could be made because the target machine actively refused it. in C:\xampp\htdocs\XMS\server.php on line 7
So, what must I filled for $host? I'm trying using website IP, it still can't connect. Maybe there's someone here have experience at this problem?
Sorry for my bad English
If you have cPanel access to the remote server then you need to mention that from which ip addresses it should allow access to MySQL..
In cPanel you will get Remote MySQL under heading Databases:
Clicking Remote MySQL will give you the option to add hosts from where you want to allow connections to your MySQL server:
Also, you can check localhost without specifying port number as value of $host..
Probably Mysql server is not allowed root access from remote servers.
you could check this post
I am trying to query a database that's on a server that I have a Remote Desktop connection to. What is required to be able to query a database on this server using my php web application.
You need:
Database server application configured to allow connections from external hosts
Server-side network configuration tuned to allow connections from external hosts (firewall, NAT, ...)
Database user, which is granted access to database you are going to use
PHP application, which connects to your database server under appropriate user
Details depend on what database server are you using.
$link = mysql_connect($host, $username, $password);
There is nothing secure at all by the way.
I use something like this, but it's far from secure. I keep it in a seperate "connection.php" that are required once by other files.
$db_host = 'INSERT IP HERE';
$db_user = 'User';
//My sql password for testing purposes
$db_pass = 'PASSWORD';
//name of the database
$db_name = 'dbname';
//connection
$conn = new mysqli($db_host, $db_user, $db_pass ,$db_name);
if (mysqli_connect_errno())
{
printf("Error connecting to DB, Errorcode: %s\n", mysqli_connect_error());
exit;
}
use answer by Merch member - the php code above .
You need to grant privileges and to create user on server you are retrieving the database data from.
Connect to mysql :
in shell type (if you are root type root or whatever username):
mysql -u root -p
enter password,
when you are logged in :
create user someusername#your-client-ip identified by 'password';
grant all privileges on *.* to someusername#your-client-ip with grant option;
now you can use php code above to connect to remote server database (ip you just used to create mysql user your-client-ip)
When you are creating php variable for mysql connect - host use mysql port in the variable if just ip not connects your-client-ip:3306
good luck