Laravel Artisan: Using a remote database - php

I am using Laravel 5.1, trying to run php artisan migrate on my local computer. I have my .env file set up with the credentials of a remote database.
However, upon running, I get an error (replaced real details for security):
Access denied for user 'user'#'44.55.66.77' to database 'db_laravel'
It appears that for some reason, it is attempting to run the command on my local IP, which is 44.55.66.77 instead of the remote database. I have already tried allowing remote access to the database from my IP, however I am still having the same issue.
I have also already attempted to connect to the database using its IP, to no avail.
Thanks in advance for your help!
Update: Okay, I read some of my host's documentation, and tried using % as a wildcard to allow any IP access to the database. I now get Access denied for user 'user'#'%' to database 'db_laravel'. However, still not sure what is going on.

This "'user'#'44.55.66.77'" means that user is connecting FROM ip "44.55.66.77", not TO "44.55.66.77".

So I solved the issue. It was a problem with my host not properly accepting the IP I entered for allowing remote access. All is well now. Thanks for all your help!

Related

MySQL connection to external database using XAMPP

I've stored a web project (PHP, HTML and CSS). I'm working inside opt/lampp/htdocs XAMPP directory, so I can run the .php files using the web browser. One of those .php files tries to connect to an external server MySQL database, but, when run:
mysqli_connect($servername, $username, $userpassword);
it displays the following warning.
*mysqli_connect(): (HY000/2002): Connection refused*
I've tried to access the database with phpmyadmin and the corresponding credentials and it works fine.
So the question is: can I perform a msqli_connect to that external database using XAMPP or I should give up?
Thanks in advance!
Since I cannot comment because of my low points, I am answering here.
I had faced similar issues before, so sharing my experience. All of the comments have suggested valuable points. These are as follows:
Use IP address instead of server name (There may be some DNS cache issue, so it is safe to use IP address).
Make sure the IP address you are using is not being blocked by the server's firewall. If possible configure server's firewall to white-list your IP Address.
The default MySQL port is 3306. Make sure the firewall is configured for allowing outside connection to the port 3306.
Most importantly, make sure the MySQL server must be configured to accept connections externally. If all of the above settings are configured properly then you should grant external access and all privilege to your MySQL User.
GRANT ALL PRIVILEGES ON 'yourDatabase'.* TO 'yourUserName'#'%';
FLUSH PRIVILEGES;
Reference - Another SO Question.

How to setup Windows Server 2008 for MySQL remote database connectivity?

I am very new to this server setup and database connectivity. I googled a lot but couldn't find the solution for it.I am developing an android application which needs to post data to remote database. Which is done.
Now i have to setup MySQL Database in the new Windows Server 2008. I have installed and managed to get access the root user(Which is fine). Now i want to access this database from my local computer[Which is iMac]. I already set the privileges by following this link. When i tried to run from my web application it shows the following error.
Error: unable to connect to database. Host 'xx.xx.xxx.x' is not allowed to connect to this MySQL server
Here is my questions
1.) How to get access to the remote MySQL database from any computer?
2.) How to run the web application in the server?Like Web Hosting i.e Do i need to setup ftp account and put the stuff over there?(For Eg: testhost.com/connecttodatabase.php by executing this it will execute whatever code in testhost server. But i have no idea how to do that for my server).
Any help is much appreciated.
Alternately, You can also try...
use the_database_name;
GRANT ALL PRIVILEGES ON
the_database_name.*
TO
'the_user_in_php_code'#'%'
IDENTIFIED BY
'password_of_the_user_in_php_code';
FLUSH PRIVILEGES;
source:
http://forums.devshed.com/mysql-help-4/host-is-not-allowed-to-connect-to-this-mysql-server-366908.html

Linux connecting to mysql PHP

I have been trying to connect to mysql all evening using PHP.
I know for a fact the username and password are correct as I have tried 3/4 and I know the permissions are set correctly in the database.
If I remote onto this machine and enter the exact same details into the commandline then i can connect to the database without issue.
The problem only seems to be with MYSQL and PHP.
A little more info:
I am trying to run a PHP app on the same server as the mysql database is on. The user has full grant permissions on the local machine. The error i am receiving is :
Fatal error: Attempt to connect to database kmc_cms on
The server is set so no remote access to mysql is available.
In your question you don't show whether you're trying IP or localhost.
Do a
show grants for <username>;
and see if the connection you're trying is even allowed.
Have you enabled remote access for the user you're trying to connect with in mysql?
I found out the issue. Within the mysql database config file there was an error which resulted in the connection allowing users from local host access only. Even though the PHP scripts were connecting using localhost it just would not authenticate. Hence I could log in using command line and not using PHP or other applications.

Hyperedit, php and mysql

I know this is not a particular php question, but it is to do with accesing php by using mysql when the file is not hosted on the same domain.
For example, im using hyperedit, the php coding tool that allows you to display the results of php in realtime as you code.
However when i try and type my mysql code in, that i know works(i tested it using my servers built in php/html etc creator) i get a error:
Connection refused (trying to connect via tcp://myservername.servername.com
Its definitely not my code, i think instead it is something to do with the fact that the file is not being hosted on the server? I have only tried it in hyperedit but i think the same would occur in other programs too.
I know its not specifically php or coding related, but i thought this is the best place to ask!
If anyone could help me it would be great!
Thanks very much!
This is because your local development machine does not have access to the mysql server in question.
If this is a shared account, you may be able to grant access to your remote machine's IP/hostname through cPanel. If you have direct access to the remote box through the cli, you can do it via a sql GRANT command, like so:
GRANT SELECT ON mydb.* TO myusername#'my_IP' IDENTIFIED BY 'mypassword';
Otherwise, it may be locked down in a shared environment where only machines on the local subnet can access the mysql server (cough, GoDady, cough).
So there's no real answer. Either you have the privileges to give your remote machine access, or you don't. If you don't, consider using another host that does allow you to do what you need.

MySql Insert doesn't work when the website deployed on the host!

I'm using XAPP under windows and my website just working well!
when I deployed it on the host server, it seems to be working normally, but the insert requests to MySql doesn't have any effect, nothing is changing on the database!
Does anyone had this issue before? is there any configuration in MySql to make it accept insert requests? or simply whats the best way to make it work!
[EDIT]
I use PhpMyAdmin, I have two tables members and notifications, I wanna configure permissions so I can Insert into the notifications table, any hint please?
thank you
check the permissions on the database server for the username and password that you are using. It can also be restricted by IP address, among others.
Indeed, the administrator can set read-only privileges for a user or for a specific table.
Check out the "grant" command for more information.
it would be helpful if you could find out the error message that MySQL is returning. check your web server log files. if you are using some shared hosting plan, there should be an option in your host control panel to see the web server log files. PHP is configured in most places so that error messages are stored in web server log files. find out what is actually happening there. it could be permissions most likely.

Categories