I've migrated a Database from cPanel to cPanel through Backup tool, But the problem is whenever i try to connect to this database for example using this TEST php code
<?php
# Fill our vars and run on cli
# $ php -f db-connect-test.php
$dbname = 'imadoulh_test';
$dbuser = 'xxxxx';
$dbpass = 'xxxxx';
$dbhost = 'localhost';
$connect = mysql_connect($dbhost, $dbuser, $dbpass) or die("Unable to Connect to '$dbhost'");
mysql_select_db($dbname) or die("Could not open the db '$dbname'");
$test_query = "SHOW TABLES FROM $dbname";
$result = mysql_query($test_query);
$tblCnt = 0;
while($tbl = mysql_fetch_array($result)) {
$tblCnt++;
#echo $tbl[0]."<br />\n";
}
if (!$tblCnt) {
echo "There are no tables<br />\n";
} else {
echo "There are $tblCnt tables<br />\n";
}
the response is This page isn’t working with HTTP ERROR 500
and the MySQL log says Got an error reading communication packets
I did try many ways to fix it but unfortunately.
Here's what I tried:
1. optimize and repair tables
2. add some code to /etc/my.conf file such as
max_allowed_packet=2684354569944
open_files_limit=10000
default-storage-engine=MyISAM
innodb_file_per_table=1
default_authentication_plugin=mysql_native_password
dealing with this article:
https://dba.stackexchange.com/questions/19135/mysql-error-reading-communication-packets
Error 500 from http means your web program -- your php program -- failed trying to send out that page. But 500 can tell us absolutely nothing about why it failed. So, moving along... You seem to be getting communication errors between php and mysql.
I believe the key words in your question are from cPanel to cPanel. That suggests you are migrating your application from server to server and maybe even from hosting-vendor to hosting-vendor.
You have imported your MySQL data from backups onto a new server with a different IP address. So, you now have two different database instances. And, it's possible you have two different instances of your php program.
So now you're troubleshooting these questions:
Can my new php code talk to my new database server? From your question it's hard to tell whether the answer is "no" or "sometimes, but unreliably."
Does my new php code run at the same hosting vendor as its MySQL database? In network engineer lingo the question is "are they on the same datacenter network?"
Is there any chance I'm trying to hit the new database from the old code, or the old database from the new code?
Some (but not all) technical support specialists at hosting companies know about this kind of thing. Call for help, but be sure the first two words out of your mouth are "I'm migrating" so they know it's a new customer and a one-time setup issue.
Related
Hi I'm running Windows 8 64bit, wamp 3.1.3 32bit, Apache 2.4.33, PHP 5.6.35, MySQL 5.7.21, and MariaDB 10.2.14
I'm building a login system and in the last 24 hours I have started to receive an ERROR MESSAGE =
Connection failed: SQLSTATE[HY000] [2002] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
Query
+-+-+-+-+-+-+-+-+-+--+-+-+-+-+-+-+-
I am using WAMP without issue for approx 5 months. I am using localhost with MySQL on a live (.IE Irish domain).
Until 24 hours ago eEverything worked OK. Now, all attempts from the localhost to connect to MsSQL fail (e.g. to search the DB for a user and verify a password).
However, if I FTP files to my domain the connection is OK and a successful connection is made to the DB.
I have read all other entries around this and similar issues. It seems quite common and (to the extent that I can understand the other replies) I cannot find a solution:-
So far I have tried:-
- Searching form.wampserver.com, Stackoverflow and youtube.
- I disabled Avast (my antivirus),
- I checked the c:...host file (it only has 5 lines),
- I do not think that any system changes have been made to my pc,
- I have not installed any new software,
- I've tried 127.0.0.1 instead of localhost,
- I've checked to see if port 3306 is available (I think it is but I'm new to this and cannot be sure I have done this correctly).
Below is a sample of a file I created to test the connection:-
(PS I know mysql is depreciated - but this was written only to test the connection!)
(PPS Obviously I've removed the real name/pw/host, etc)
<?php
$dbname = 'dbname';
$dbuser = 'username';
$dbpass = 'password';
$dbhost = 'dbname';
$connect = mysql_connect($dbhost, $dbuser, $dbpass) or die("Unable to
Connect to '$dbhost'");
mysql_select_db($dbname) or die("Could not open the db '$dbname'");
$test_query = "SHOW TABLES FROM $dbname";
$result = mysql_query($test_query);
$tblCnt = 0;
while($tbl = mysql_fetch_array($result)) {
$tblCnt++;
#echo $tbl[0]."<br />\n";
}
if (!$tblCnt) {
echo "There are no tables<br />\n";
} else {
echo "There are $tblCnt tables<br />\n";
}
?>
Any attempt to connect to MySql from wamp/localhost generates the error. But if the file is FTP'd to a real domain it successfully connects and prints the number of tables in the DB (which is 6). Therefore, there are no mistakes in the url/db/username/pwd, and I don't believe there are any changes with PHP/MySQL set up on my domain.
Also as the file works when put on a live server, the username/pw, db, etc are all correctly spelt.
Finally, I have been saving different versions of my website in development. Each of the last 6 versions have worked without any issue. Now none of the earlier versions of the login system work. This means that I can rule out any mistake made in the recent version of the website.
I'm a newbie and I'm stuck. I hope not to get roasted if this in fact turns out to be a repetition of another question/response. I have done my best to find an answer before posting this.
Any help would be Greatly appreciated...
This question already has answers here:
Why shouldn't I use mysql_* functions in PHP?
(14 answers)
Closed 4 years ago.
I have a mySQL database hosted locally using WAMP, I went through all the procedures to access it remotely and seem to have succeeded in that I can put the IP address into my phone, see WAMP and access phpmyAdmin etc.
My issue is that I want to test the database connection using the script below from my website (ultimately I want to use a WP plugin to get info off the DB and then close it).
However I am not fully sure what the parameters would be.
Apache server is on port 80 and mysql is on port 3306. I have setup port forwarding on those ports and tested them using http://www.canyouseeme.org/
Therefore would my host be myIP (using What is myIP) : 80 or 3306.
I have tried both and they fail. Would my user name be root or Root#Host
Like I say ultimately I want to test this, connect to the database and then use the parameters in a WordPress plugin to copy data from my locally hosted DB to my site's db.
Please advise.
Thank you.
<?php
# Fill our vars and run on cli
# $ php -f db-connect-test.php
$dbname = 'name';
$dbuser = 'user';
$dbpass = 'pass';
$dbhost = 'host';
$connect = mysql_connect($dbhost, $dbuser, $dbpass) or die("Unable to Connect to '$dbhost'");
mysql_select_db($dbname) or die("Could not open the db '$dbname'");
$test_query = "SHOW TABLES FROM $dbname";
$result = mysql_query($test_query);
$tblCnt = 0;
while($tbl = mysql_fetch_array($result)) {
$tblCnt++;
#echo $tbl[0]."<br />\n";
}
if (!$tblCnt) {
echo "There are no tables<br />\n";
} else {
echo "There are $tblCnt tables<br />\n";
}
Make sure your router is allowing the port forwarding. If the (ip address) xxx.xxx.xxx.xxx:80 is not showing anything then, ports are not being forwarded properly. Here are some check you could make to see where the problem lies:
See if it's working on the local machine at 127.0.0.1 (most likely it will work in your situation).
Check on other devices on your network such as using your smartphone go to your machines local IP address and see if that works.
If both of the above work, then you need to make sure your router is port forwarding the correct IP Address and Ports.
This sounds like a stupid question, but I'm beginning in PHP and MySQL and failing at the first step, trying to connect to the database:
<html>
<head>
</head>
<body>
<?php
$con = mysqli_connect("localhost", "root", "root", "ASOIAF.odb");
if (mysqli_connect_errno()) {
echo "Failed to connect to database";
} else {
echo "Connected to database";
}
mysqli_close($con);
?>
</body>
</html>
I don't understand the first host parameter. A yahoo help page said that the host should be "mysql", but when I used this it failed to connect as well. The database, ASOIAF, is in OpenDocument database format (odb), on LibreOffice Base. I'm using Uniserver to run PHP and MySQL; both are currently running. The web application is stored in Uniserver's www folder, and run on Google Chrome through localhost.
What should I be inserting in the host portion of the connect statement? Or have I made a more basic syntax error in the PHP code that is preventing a connection from being made?
What is my host name for MySQL?
We don't know what you have called the computer you are running MySQL on.
A yahoo help page said that the host should be "mysql"
That is specific to Yahoo Web Hosting. It doesn't sound like you are using their service, so that is inapplicable.
I'm using Uniserver to run PHP and MySQL
That suggests the computer running the webserver running PHP and the computer running the MySQL server are the same machine. That makes localhost appropriate.
localhost is the standard name given to a computer on the private network that only it connects to. For MySQL is has a special meaning and causes the connection to be made via a socket instead of TCP/IP (which is more efficient).
What should I be inserting in the host portion of the connect statement?
localhost if the above is correct.
Or have I made a more basic syntax error in the PHP code that is preventing a connection from being made?
I can't see any syntax errors. I suspect the problem may be down to your database configuration. Have you told the MySQL server about ASOIAF.odb? Is that what the database is actually called inside MySQL (as opposed to just being the file that stores the configuration for LibreOffice to connection to that database).
Your biggest mistake is not using mysqli_error to find out what problems PHP is reporting.
if (mysqli_connect_errno()) {
echo "Failed to connect to database";
echo mysqli_error();
use
mysqli_connect("localhost", "root");
Hope it will work
I have two servers setup on Amazon AWS. One server is running PHP and the other has MySQL. I can connect to the MySQL database through my terminal and MySQL Query Browser.
I am trying to get a connection between the PHP and MySQL servers.
Here is the PHP Code that I am using (works for "localhost" databases)
$dbbase = 'mydb';
$dbuser = 'myuser'; // Your MySQL username
$dbpass = 'mypassword'; // ...and password
$dbhost = 'localhost:3306'; // Internal IP for MYSQL Server
// connect to database
$dblink = mysql_connect($dbhost, $dbuser, $dbpass)
or die ("System Down");
mysql_select_db($dbbase, $dblink)
or die ("Database Down");
It is my understanding that I should be able to route this an internal AWS traffic, but at this point I will take anything that works and build from there.
Here is what I have done:
Added the ip of the PHP server to the Security Group for MySQL(3306) permissions
Tried to use the internal, external, and private IPs/DNSs of the MySQL Server as the $dbhost variable
Created myuser#% (wildcard) on thy MySQL server
Any ideas or tips would be much appreciated.
I had the same issue - turns out MySQL extension for PHP is NO longer included in PHP5!
"In PHP 5 (updated PHP 5.0.4), the following changes exist. Built in: DOM, LibXML, Iconv, SimpleXML, SPL and SQLite. And the following are no longer built in: MySQL and Overload."
Source: http://php.net/manual/en/install.windows.extensions.php
I've got this working.
I think the big trick was to add this rule to the Security Group:
Type: MySQL
Source: 10.0.0.0/8
My understanding is that 10.0.0.0/8 covers all internal amazon IPs. I think you could tighten this up, but it is possible for the internal IP of your servers to change, so that would need to be managed.
Then in my PHP script I used the Private DNS of my MySQL Server. It should look something like this: ip-10-10-100-100.ec2.internal:3306
In the end, I think that is everything that I did.
I have a database set up on a godaddy server. It is configured to allow remote access, and there are a couple of websites I'm running which need to access this data. It works when accessed from another godaddy site, and I can connect from my development environment both at work and home. We recently set up hosting with mydomain.com.
Here is the code block that triggered it:
function connect(){
$servername = "XX.XX.XXX.XX";
$dbusername = "databaseusername";
$dbpassword = "mahpassword";
$dbname = "databasename";
try{
$newMysql = new PDO("mysql:host=".$servername.";dbname=".$dbname, $dbusername, $dbpassword);
}
catch(PDOException $e){
echo 'connection Failed: '. $e->getMessage();
die;
}
}
and now I'm getting this error message on the new site:
connection Failed: SQLSTATE[HY000] [2003] Can't connect to MySQL server on 'XX.XX.XXX.XX' (111)
The only problems I can think of is that either for some reason there are a limited number of IP addresses the MySQL database will connect to by default (which seems squirrely), I'm getting blocked by a firewall on the MySQL server (again.. doesn't make sense to me), or there is some setting on the mydomain hosting server disallowing remote requests (?)
I'm new to this kind of thing, so I'm open to any suggestions. I could probably just set up another database on the new site, but I don't want the hassle of keeping them synchronized if I don't need to. What might be wrong? Are there any workarounds?
[edit]
connected to remote database via console (mysql -h XX.XX.XXX.XX ...), the privileges were found under the information_schema database, a quick select * from SCHEMA_PRIVILEGES and select * from USER_PRIVILEGES shows that 'databaseusername'#'%' has sufficient privileges. Not that it helped me any, but maybe it'll help someone down the road.
[/edit]
As it has been more than a year since I asked this question, I suppose I need to answer it just to close it.
It turns out that godaddy had blocked mydomain.com servers via firewall ("Remote access" was limited). so in order to accomplish what I wanted to do, I had to copy and store the database on both sites.