I'm starting a large project in Laravel 5. In the past I used XAMPP for all local work. Now we're going to work in Homestead. I got Homestead set up and running and I booted up a Laravel 5 project in it. works fine.
Because of various reasons we do NOT want to use Laravel migrations but are using MYSQL workbench in combo with XAMPP-PHPMyAdmin for work on the mysql database. My question is: how can I access this mysql database from within the Homestead VM?
I tried all kinds of settings in the app/Config/database.php. but none work.
I looked around for related questions here, but none seem to answer the base of my question: is it even possible to access a remote database (or one on my host machine) from within homestead?
I read somewhere that I can create migrations from an SQL dump to duplicate the DB in homestead using a package (https://github.com/Xethron/migrations-generator). using this as a workaround, I could connect my Laravel app to my DB I have set up in XAMPP, generate the migrations, then connect back to the Homestead DB and finally run the migrations. I think this could work but I would prefer direct connection. any suggestions on how to connect to a database outside the Homestead VM would be welcome.
<1>Open .env (can be found in root of laravel)
<2>Change DB_HOST to your LAN IP address(something like 198.168.0.11)
DB_HOST=LAN_IP
<3>Now go to phpmyadmin and in privileges tab
Add new user and fill login info
Select host as any_host(or fill host with your PC name)
I am also relatively new to Laravel and Homestead too but have had some luck with it.
First I'm not sure it's such a great idea not to use the MySQL instance inside Homestead but if you have your reasons I'll take you at your word. That said from your "Homestead" directory you can "vagrant ssh" into your Homestead VM.
Here you can mysql -u homestead -psecret dbname into your database and configure it at will just as you would your XAMPP instance. If you are using Laravel models as long as they match the database you'll be fine.
To your point of connecting to another database from within the VM have you tried to connect to that outside database from the command line? As long as your XAMPP MySQL instance is configured to receive remote connections and you have a user properly configured you should be able to test from the command line from within the Vagrant VM. See below where 192.168.1.196 is the IP address of the box/VM containing the MySQL instance to which you want to connect. I'm not running XAMPP but I was able to make a connection from within Vagrant Homestead out of the VM to another MySQL instance running on my local machine by providing my local network address. "127.0.0.1" won't work obviously because the Vagrant VM will perceive that as itself.
mysql -u user -ppassword dbname -h 192.168.1.196
Hope this helps.
Related
I am a bit of a newbie and new to the php coding world and have a small task I am trying to find an answer to, but I cannot seem to find the relevant question asked anywhere before.
Basically I have a server where I create reports from mySQL DBs located on other remote machines.
So far these other servers have had a basic mysql server running on them and I can easily connect to them with PDO like this:
$DBcon = new PDO("mysql:host={$DB_host};dbname={$DB_name}",$DB_user,$DB_pass);
$DBcon->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
But I now have a server running mySQL inside of a docker container on this remote server.
So my question is, is it possible to connect to this mySQL db as well using PDO?
I am able to connect to the DB remotely with mySQL workbench using Standard TCP/IP over SSH (as I also do with the other servers), but the one thing I have to specify differently here compared to the other servers not using docker is the 'MySQL server host relative to the SSH server'. Usually just having 127.0.0.1 here is fine, but with mySQL inside a docker container I first have to find this relative address with
docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' database-name
you then get something like 172.21.0.5 and add this in that field
workbench connection
How are you able to represent this small change in the PDO statement? Is it still possible to connect in this way?
actually, no. You can't connect inside code as mysql workbench over ssh. But you can use ssh jumb for this connection as below link.
https://www.tecmint.com/access-linux-server-using-a-jump-host/
You should configure jump command to a mysql servers with port. this jump command provides your connection via bastion you mentioned instance for ssh to the mysql server.
for example: ssh -N -i pemfile.pem(if you have to connect to jump server) -L fakemysqlserverip:3306:mysqlserverrealip:3306 ec2-user#jumpserverip
fakemysqlserverip may be localhost,127.0.0.1 or different
jumpserverip is your server which is for using over ssh
Regards
I am facing a strange problem with my docker. I had to reinstall it as in the following link: Docker Installation on Ubuntu 18.04
I did this installation before, so everything worked out fine. Then I created the network like this:
docker network create --subnet=172.18.0.0/16 mynet123
And finally built my container. But it can't connect to a database remote server. It gives the following error:
So I checked my internet connection from inside docker container and it turned out that I don't have it. So I guess that's the root of the problem. I tried reinstalling docker, changing docker network by specifying other subnet, followed this instruction
Stackoverflow solution
But still no result. Does anybody have an idea how I can sort this out?
By the way, this is how I connect to MySQL using python:
dbconn = mysql.connector.connect(host=config["mysql"]["host"], database=config["mysql"]["database"], user=config["mysql"]["user"], password=config["mysql"]["password"])
cursor = dbconn.cursor()
And here is my config:
[mysql]
host = X.X.X.X.
database = database_name
user = root
password = password
*X.X.X.X here is an IP address of the remote host
P.S. I can connect to the remote database from my local machine, containers can connect to the database server via default network. All user permissions in my database are given.
I installed LAMP on a VM instance on Google cloud but when i try to access mysql database remotely from my linux terminal using
$ mysql -u username -h ipaddress -p
after entering password nothing happens (no error). I tried accessing it locally via ssh it works.
Is there any other setting on cloud platform. I need to change before accessing database from a remote pc. Followed this tutorial but it just stops after entering password.
Tried commenting out bind address but didn't work. Need help.
Just to be clear, are you using the mysql command on your remote machine or through SSH?
Normally, you should never allow external access to remote MySQL for security reasons, especially if the only app accessing the data is local. (however, it's unclear if that is the reason why you can't connect)
This is how you should connect:
Connect to your remote VM using SSH (ex: ssh user#ipaddress)
THEN, connect to your MySQL instance.
When connecting using a DB editor, some editors allow MySQL connections through SSH. Sequel Pro for Mac does this very well.
I'm currently trying to run an application on a server but my customer is very 'picky' about their data and wish to store the database on their own internal office server. I've installed MySQL and can get the application to run locally but for a few specific reasons the application needs to run else where.
I basically can't get access to MySQL from a different location. I think my main stumbling block is port forwarding to the correct location. MySQL is installed on a mac mini with local IP address 192.168.1.242 and the router/modem is an Apple Time Capsule. I've tried looking at tutorials but they all have options that I don't have access to. I've attached a screenshot of the options I have access to and the settings I've tried so far.
Other information possibly needed is:
I need to connect from PHP
I've set a user up within MySQL with a wildcard (%)
I'm testing it using the following: command on my local machine in CMD: mysql -u username -h remote_ip_address -p
I get the following error: ERROR 2003 (HY000): Can't connect to MySQL server on 'REMOTE_IP_ADDRESS' (10061)
Firewall is turned off completely on the Mac Mini
There is nothing in the my.cnf file
OS is Sierra
That's all I can think of at the moment but any advice would be greatly appreciated and any more information required can be provided.
PS. evidently I'm not very good with MAC machines/networks
For anyone that reads this I had a very specific issue. I installed MySQL using homebrew. Homebrew binds MySQL to 127.0.0.1 therefore will only allow connections to MySQL from the same machine no matter what you try to do. To fix it I've had to edit /usr/local/Cellar/mysql//homebrew.mxcl.mysql.plist and replace --bind-address=127.0.0.1 with bind-address=*.
MySQL has an internal firewall of users/IPs. Even if you can connect locally, you might not have permission remotely:
Try this as root user on the MySQL server (locally first!)
GRANT ALL ON <db>.* TO '<user>'#'<remoteIP>' IDENTIFIED BY '<password>';
Where
<db> is the name of the DB
<user> is name under which you connect
<remoteIP> is your external office IP FROM which you are trying to connect
<password> should be self-explanatory!
This will explain the options better
Weird issue. Can't connect to localhost MySQL database from command line, but I can through MySQL program, Sequel Pro. Any ideas why? I entered the same user/password, but I'm getting a access denied error for root#localhost
Extra question: can you run MySQL commands within Sequel Pro? I'm pretty new to MySQL, but I'm just trying to change a simple column definition.
EDIT: reset password from within Sequel Pro query for root, and was able to get it working.
MySQL has different accesses. You can allow a MySQL database to only serve requests from a specific machine, or only from the local machine.
However, note that MySQL differentiates login from "localhost" and from "127.0.0.1".
Try allowing both localhost, 127.0.0.1 and "%" to the account.