mysql_connect access denied error when trying to access remote database - mysql

I'm trying to connect to a remote database. Here's my code:-
php $con = mysql_connect("2toria.com","username","password"); if (!$con) { die('Could not connect: ' . mysql_error()); }
mysql_select_db("myTable", $con);
$result = mysql_query("SELECT * FROM Contestants");
while($row = mysql_fetch_array($result)) { echo $row['Name']; echo "<br />"; }
mysql_close($con);
The database, table, username and password names are all correct (I've changed them here for obvious reasons), but I'm getting the following error:-
Warning: mysql_connect() [function.mysql-connect]: Access denied for
user 'username'#'bluechip6.ukhost4u.com' (using password: YES) in
/home/toriaco/public_html/bigbro/index.php on line 9 Could not
connect: Access denied for user 'username'#'bluechip6.ukhost4u.com'
(using password: YES)**

First possible reason:
I know antagonist (a Dutch hosting service) blocks all connections that are not from localhost for security reasons, and I don't think they are the only ones. (So always connect to localhost, not a http://... URL!)
Second possible reason:
The password/username is wrong.

Related

fix access denied for root'#'localhost' (using password: NO) in init.php on line 2

I have an e-commerce website, and I m trying to move from localhost windows to Linux Mint. the problem is that I can't connect to database.
I see my config.inc.php in lampp/phpmy admin and the username is root and password = ""
I don't know how to fix this.
<?php
$db = mysqli_connect('127.0.0.1', 'root', '', 'ecommerce');
if(mysqli_connect_errno()) {
echo 'Database connection failed with following errors: '.mysqli_connect_error();
die();
}
require_once $_SERVER['DOCUMENT_ROOT'].'/ecommerce/config.php';
require_once BASEURL.'helpers/helpers.php';

I cant connect to my MYSQL Database using Php

Hi i have a problem connecting with my Mysql database i have the following code:
<?php
$servername = "dt5.ehb.be";
$username = "TVOSAPP";
$password = "*****";
$dbname = "TVOSAPP";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "SELECT storyId, title, score FROM Stories";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
echo "id: " . $row["storyId"]. "Naam" . $row["title"]. "score" . $row["score"]. "<br>";
}
} else {
echo "0 results";
}
mysqli_close($conn);
?>
which gives the following error:
Connection failed: Access denied for user 'TVOSAPP'#'10.3.101.30' (using password: YES)
I hope you can help me out to solve this problem it would be very much appreciated
the user that you are trying to connect with might not have the permission to connect remotely to the DB. please verify the same. To give remote access you might need to run
grant <privilage name> on TVOSAPP.* to 'TVOSAPP'#'<youripaddress>' identified by <yourpassword>
Ref: http://dev.mysql.com/doc/refman/5.7/en/grant.html
EDIT:
If your IP address is not static then you can use a percentage sign (%) in place of your IP address. However this approach is less secure as it allows any host to connect to the database remotely.
I fixed it about a week ago is had a space too much thats why I couldn't connect thank you all for your responses

Perl codes always connecting to same MySQL database although it is configured to connect to different server

Perl codes always connecting to same MySQL(local but in error showing FQDN of server) database although it is configured to connect to different server.
please see the codes.
$datasetname="DBI:mysql:database=applications;host=entdb"
$$dbobject = DBI -> connect ($datasetname, $username, $password,
{RaiseError => 0, PrintError => 0})
or $errflg2 = 1;
print TT (" : ".time()."\n");
close (TT);
if ($errflg2 > 0)
{
$errmsg = "ERROR opening up the database: $datasetname\n";
$errmsg .= " Error number: " . $DBI::err . "\n";
$errmsg .= " Error text : " . $DBI::errstr . "\n";
print "$errmsg";
ilog ($ifile, $errmsg);
mail_it ($errmsg);
if ($debug != 0) { close (DB); }
exit (1);
}
else
{ print "Opened the '" . $datasetname . "' database.\n"; }**
enter code here
error
ERROR opening up the database: DBI:mysql:database=applications;host=entdb
Error number: 1045
Error text : Access denied for user 'entdb'#'vpl121' (using password: YES)
see in code i referred entdb, but Perl connecting to VPL121. Perl codes are running on vpl121.
In mysql all user accounts are identified via username#hostname format, where hostname is the host name or ip address of the computer from which the code connects to the mysql database.
You did write that the perl code runs on vpl121, therefore this is the hostname that mysql uses. Apparently, you do not have any user account that matches the 'entdb'#'vpl121' or the password is incorrect or the given user does not have access to the entdb database.
My guess is that you do not have any matching user accounts. Consider perhaps creating an 'entdb'#'%' user account, where % as hostname stands for any host name or ip address.

Access denied for user 'root'#'localhost' (using password: NO)

i created a simple db connection in my php page and its working fine since its not showing any error while executing this
<?php
$link = mysql_connect('www.ccccccccccccc.co.uk', 'cccccccccc', 'accccc');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
/*echo 'Connected successfully';*/
echo "DB : <font color='green'>ACTIVE</font>";
mysql_close($link);
?>
The problem is the page is showing error Access denied for user 'root'#'localhost' (using password: NO) while executing
<?php
$q = mysql_query("SELECT slno, name, idno FROM $memlist") or die(mysql_error());
echo "<table><tr><th> NO</th><th> NAME</th>
<th> ID NO</th></tr>";
while($row = mysql_fetch_array($q)){
extract($row);
echo "<tr><td>$slno</td><td>$name</td>
<td>$idno</td></tr>";
}
echo"</table>";
?>
i am working on server directly not on local host
You don't appear to be connecting to the database in the second piece of code, so it's trying to connect with default settings (which obviously won't be correct due to security concerns).
As for the first block of code, you're closing the connection immediately after opening it, which is kind of pointless.

MySQL failing to establish a connection

I recently created a webpage, while using an usbWebserver, so basically a local server.
Yesterday, I have purchased a domain and hosting, and I wanted to move my files onto the server.
I have changed my username, password and url, however I cannot get the mysql_connect to work.
<?php
$mysqlhost = "mysql04.totaalholding.nl";
$user = "a";
$passwd = "";
$mysql = mysql_connect($mysqlhost, mysql_real_escape_string($user), mysql_real_escape_string($passwd));
if (!$mysql) {
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db('a_turfjes', $mysql);
if (!$db_selected) {
die('Could not connect: ' . mysql_error());
}
?>
The above code is how I connect to the database, which should work. (please note that a is not my username and neither is my password empty).
These are the properties of the database:
DATABASE: a_turfjes
Extern MySQL Host: mysql04.totaalholding.nl
Users: a_admin
I am not quite sure which username to use should I use the username and password from cpanel (which is required to access PHPMyAdmin), or the username and password, which is the user of the database itsself.
I'd like some help on this error. When accessing my index.php (which includes db.php (which is the file above)), I receive the following errors:
Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'root'#'localhost' (using password: NO) in /home/a/public_html/turfjes/db.php on line 8
Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in /home/a/public_html/turfjes/db.php on line 8
Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'root'#'localhost' (using password: NO) in /home/a/public_html/turfjes/db.php on line 8
Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in /home/a/public_html/turfjes/db.php on line 8
Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'root'#'www30.totaalholding.nl' (using password: NO) in /home/a/public_html/turfjes/db.php on line 8
Could not connect: Access denied for user 'root'#'www30.totaalholding.nl' (using password: NO)
Use the username and password of the database itself not the cpanel.
Test connection using:
$mysql_host = "localhost"; # Usually doesn"t need modified
$mysql_db = "a_turfjes"; # Database name
$mysql_user = ""; # Username
$mysql_pass = ""; # Password
$link = mysql_connect ($mysql_host,$mysql_user,$mysql_pass);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
If successful, access records:
$query = "SELECT * FROM TableName";
$result = mysql_db_query ($dbname, $query, $link);
Use the database username and password. If the database is hosted in another server please give the host name to that server name