I'm trying to connect to remotemysql on another server and i've all the authentications and these authentication are working well to connect to remote sql in VISUAL STUDIO and PHP STORM but when i open up the url royalresidency.pk/administration and try to login and it gives me this error i don't understand this error i tried to allow that from from remotesql also and also this ip is allow but still i can't get access to sql from this server what can be the issue ?
$connect = new PDO('mysql:host=65.60.37.227;dbname=cricflip_RoyalResidency',$dbuser, $dbpass);
return $connect;
Try to check your mysql connection. Try connecting with command line. (Mysql should be preinstalled in your system)
mysql -u USERNAME -pPASSWORD -h REMOTE_SERVER_IP DB_NAME
Related
I am trying to host a PHP-based website on Heroku. For that, I'm using ClearDB as my online database
For doing so, I added a new code to config.inc.php in C:\xampp\phpMyAdmin:
The code is as follows:
/* Heroku remote server */
$i++;
$cfg["Servers"][$i]["host"] = "*pasted hostname*"; //provide hostname
$cfg["Servers"][$i]["user"] = "*username*"; //user name for your remote server
$cfg["Servers"][$i]["password"] = "*password*"; //password
$cfg["Servers"][$i]["auth_type"] = "config"; // keep it as config```
After doing this and refreshing my XAMP, I was able to get an option to choose the server I want to shift to, but when I click it, I was getting the error that I'm showing above.
Server gone away is a generic error, the actual issue is that you're using invalid settings to try and connect to it.
On the host running phpmyadmin, you should try connecting to the mysql server using the mysql command
Something like mysql -h SomeHost -u root -p and debug that way before plugging the information back into PHPMyAdmin
I'm using phpseclib to connect to mysql database with php for my app.
I can connect to mysql with workbench using TCP/IP over SSH without a problem but I can't connect my code to it.
I'm creating a ssh connection first and then I start with mysql connections and querys but I have this error
mysqli_connect(): (HY000/1045): Access denied for user 'root'#'localhost' (using password: YES)
I've found some people using a command like "$ssh->exec('mysql -u user -p password') to connect to mysql but after that, how can I do all my querys? as I understand, the "exec" command is as send commands to the server console?
Here is my code, I hope you can help me:
This is conexion.php
include('Net/SSH2.php');
include('remote_conexion.php');
$db_host="127.0.0.1";
$db_user="root";
$db_password=" ";
$db_name="mascotas";
$ssh = new Net_SSH2($host);
if (!$ssh->login($sftp_user, $sftp_password)) {
exit('Login Failed');
}
$connection = mysqli_connect($db_host, $db_user, $db_password, $db_name);
And this is remote_conexion.php (ignore the "sftp" things, I'm using that for manage files)
include('Net/SFTP.php');
$host="***.***.**.***";
$sftp_user="user";
$sftp_password="*******";
$port="22";
$sftp = new Net_SFTP($host);
if (!$sftp->login($sftp_user, $sftp_password)) {
exit('Login Failed');
}
phpseclib doesn't (currently) support tunneling. And even if it did you wouldn't be able to use mysqli_connect - you'd have to have a pure-PHP MySQL implementation, kinda like https://github.com/amphp/mysql .
In lieu of that the best you're gonna be able to do (with phpseclib) is something like this:
echo $ssh->exec('mysql -uUSER -pPASSWORD DATABASE -e "SQL COMMAND"');
connect to the mysql database using phpseclib library talks about how to improve on that slightly but even with that you're not going to be able to make use of (for example) prepared statements or even mysqli_real_escape_string.
The best solution, imho, would be to use something like AutoSSH
I've read all your answers and I tried to connect from the traditional way, without using the ssh functions. Just like this:
$connection = mysqli_connect($host, $db_user, $db_password, $db_name);
Using the server ip as "host", the username and password from mysql but I got this message now:
mysqli_connect(): (HY000/2002):An error occurred during the connection attempt since the connected party does not respond after a period of time, or an established connection error occurred that the connected host has not responded.
This way works when I'm using localhost, but not in this case with the remote server.
All the login data it's ok, I can connect to database via workbench without a problem (I have to connect with workbench using TCP/IP over SSH) but I don't know why I can't connect with php.
I am attempting to connect to MySQL server on my personal computer (Ubuntu 18.04.1 LTS) from a web browser, using url: http://localhost/Test.php
In Test.php I have the following code:
$pdo = new \PDO("mysql:host=localhost;dbname=mydatabase", "root", "password");
I can connect successfully using command line mysql -u root -p (and use USE, SELECT, UPDATE...). Mysql service is running.
Any idea of what's wrong?
Solved. I just created a new user, example:
CREATE USER 'select_user'#'localhost' IDENTIFIED BY 'password';
GRANT SELECT ON *.* TO 'select_user'#'localhost';
And changed user "root" to "select_user" in my php code.
Using user "root" was the problem.
I want to run PHP script in local system (localhost) and the data to be stored in the server database. I'm getting an error while connecting to remote mysql database from localhost through PHP script.
Warning: mysql_connect(): Access denied for user 'XXXX'#'ip address' (using password: YES) in E:\xampp\htdocs\New\example\include\config.php on line 13
I tried using
$con= mysql_connect("example.com:3306","db username","password");
mysql_select_db('db', $con);
I tried using mysqli_connect(...) also but I couldn't connet.
somebody please guide me how can I resolve this?
If you are running it on Localhost then do it like this
$connection = mysqli_connect('localhost','username', 'password', 'database');
When you use mysqli you don't need to use the mysql_select_db as this information is passed in when you create the connection.
The main fix that I will stress here is using your first credential passed into the connect variable as 'Localhost' if its local on your machine and you are using xampp or mamp etc then use localhost.
this syntax that you have done mysql_select_db('db', '$con') is wrong when using mysql you DO NOT need to pass a $connection variable into mysql as this only applies for the new mysqli.
Last word of advice as soon as your comfortable (preferably asap) move away from mysql functions and use mysqli, the move is not too different you just have to learn where to pass in the $conn variables.
Seams like you have not granted privileges to user.
Try this on your remote database.
~$ mysql -u root -p
Enter Password:
mysql> grant all privileges on *.* to user identified by 'pass' with grant option;
Oh, check out Kenziiee Flavius answer first - that might already solve your problem as you are on localhost.
Log in to your Server via commandline:
mysql -u username -p
Create a new user for your remote host:
CREATE USER 'username'#'192.168.0.1' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'username'#'192.168.0.1';
Replace 192.168.0.1 with the ip or hostname of your remote host.
How to log with a diferent user in a MYSQL remote database?
Here's what I've done:
Logged as root in the MYSQL:
'create user 'user'#'%' IDENTIFIED BY 'password';
'grant select on *.* to 'user'#'%';
Then I setted a PHP script which connection is this one:
$con = mysql_pconnect("xxx.xx.xxx.xxx","user","password");
$selected = mysql_select_db("database",$con);
Aaaand it isn't working:
I'm using LAMP on a cloud server, by the way;
Warning: mysql_pconnect() [function.mysql-pconnect]: Can't connect to MySQL server on 'xxx.xx.xxx.xx' (10061) in D:\path\index.php on line 21
What am I doing wrong?
EDIT: Not a firewell issue;
You might want to check the MySQL documentation on this specific problem. If I had to guess, I would say that your MySQL server may be bound only to the local (127.0.0.1) address. To troubleshoot you should probably try connecting to the server using the command line MySQL client in order to get a better idea of why exactly the connection isn't being made.
Seems to me like a firewall issue. You should check if the machine hosting the MySQL server allows connection on the port 3306 from external IPs as well.
Check if the server you have to connect to has the firewall open on the port you are trying to connect... default port is 3306
you can use
mysqladmin -h localhost
to see check what is the port mysql is using