I can connect to mysql server with ssh .
# mysql -u username -h 185.2.3.80 -ppasword
output is :
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 280
Server version: 5.1.61 Source distribution
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
I want to connect to mysql server with php :
<?php
$servername = "185.2.3.80";
$username = "username";
$password = "password";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
this is output :
Could not connect: Can't connect to MySQL server on '185.2.3.80' (13)
I turn off firewall with iptables and remove bind-address and skip-networking from my.cnf .but can not connect with php .
try it
<?php
$servername = "185.2.3.80:<server Port>";
$username = "username";
$password = "password";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
write your server port in my case it is 3306.
Do one thing more go to your Cpanel -> remote mysql then add a percentage wild card to allow online access to your database.
You forgot the database name.
First set your database name in a variable
$databaseName = '/* The name of your database */';
Try this :
$conn = new mysqli($servername, $username, $password, $databaseName);
Refer to the documentation
I found solution.ssh can connect to mysql server but httpd can not connect mysql over network.I make httpd to can connect to mysql server over the network with :
sudo setsebool -P httpd_can_network_connect=1
Related
$servername = "localhost";
$username = "jaskaran";
$password = "India#123";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
jaskaran has all access mysql and when i try with
mysql -u jaskaran -p it is working fine by when i try with php it does not why
error is The server requested authentication method unknown to the client
even i try this also
ALTER USER 'jaskaran'#'localhost' IDENTIFIED WITH mysql_native_password
BY 'India#123';
I have bought a database MySQL to use on my domain/host.
I can connect to the database via wampserver (localhost) without problems.
But when I am trying to connect to the host website it gives me an error.
Connection failed: Can't connect to MySQL server on 'mysql-******.net' (111 "Connection refused")
My code:
<?php
$servername = "mysql-*********.net";
$username = "username8954";
$password = "dolphyn1235";
$dbname = "animals";
$dbServerPort = "26313";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname, $dbServerPort);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
Any ideas how to solve this?
Check in your MySQL Server configuration files (my.cnf), find bind-address = 127.0.0.1 then comment them with # at the begining of the line. and then restar your MySQL.
Connection failed: 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.
as i establish connection between my computer and remote machine using "php" and sql server 2008 respectively. i got this error.
<?php
$servername = "";
$username = "";
$password = "";
$dbname = "complaint";
// Create connection
$conn = new mysqli($servername, $username, $password,$dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
?>
You must have a defined servername, username and password. If the server is local than use "localhost" if it is a remote server use IP "X.X.X.X"
I have one project running a database on a Cloud9 project. I have created a mobile app which will need to connect to the database by POST to a PHP file which will then run the following code:
$servername = "myusername-projectname-somenumber";
$port = 3306;
$username = "form";
$password = "password";
$dbname = "dbname";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname, 3306);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
I got the servername by using this in the terminal:
SHOW VARIABLES WHERE Variable_name = 'hostname';
I am getting an error from the other project:
Connection failed: Unknown MySQL server host 'myusername-projectname-somenumber' (0)
***Note: I have replaced myusername-projectname-somenumber and dbname for posting this. I did not forget to fill them out.
Thanks for the help!
I am trying to connect to a MySQL database using PHP using the following code:
<?php
$servername = "localhost";
$username = "root";
$password = "pass";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
When using localhost, I get a message
Connection failed: No such file or directory
When using 127.0.0.1 for the host, I get
Connection failed: Connection refused
I have confirmed that I can connect using the command line, and the output is below
mysql -u root -p pass -h localhost
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7282
Server version: 5.5.47-0ubuntu0.14.04.1-log (Ubuntu)
Connecting using TCP
mysql -u root -p pass -h 127.0.0.1
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7318
Server version: 5.5.47-0ubuntu0.14.04.1-log (Ubuntu)
The following is the relevant mysqli section of the php.ini file in /etc/php5/apache2
mysqli.default_port = 3306
mysqli.default_socket = /var/run/mysqld/mysqld.sock
mysqli.default_host = 127.0.0.1
And the settings from /etc/mysql/my.cnf
[mysqld]
#
# * Basic Settings
#
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
.
.
.
bind-address = 127.0.0.1
I have tried using PDO to connect to the database with the same results. Can anyone see a configuration setting that is not correct, or have another idea of what could be wrong?
Edit: I installed phpmyadmin and it connects to MySQL with the same settings.
Try to do this?
<?php
$servername = "localhost";
$username = "username";
$password = "password";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>