Redirect mysql server using /etc/hosts
Hi,
I have a PHP script that runs on my Webserver and connects to my MySQL server. So far nothing special.
But for code development I have a local copy of my script and of my database on my laptop.
But now the address of the MySQL server in my PHP script points to the wrong direction. It still points to
my Web-MySQL-Server (e.g. mysql.example.org) but my development MySQL server runs on localhost.
Of course I could simply change the PHP script and change the name of the server, but than I have to remember
to do this every time I up or download the script.
Therefor, I tried to redirect the MySQL server DNS name in the file /etc/hostsmysql.example.org localhost
That would be no problem for me because I never connect the server directly from my laptop (only through scripts
that run on the remote Webserver).
Unfortunately this does not work and I do not understand why.
If I change the server name in the script everything works fine.
If I change the /etc/hosts file the script says it could not connect to the server.
I hope you can help me to understand what I did wrong.
Thanks a lot and best regards,
Michael
Comments
-
hi
please try 127.0.0.1 instead of localhost:dry:0 -
Thanks for the idea, but unfortunately this does not work. It still get an error from my apache that it cannot connect to mysql.0
-
Do you have any odd rules in your firewall that may be restricting loopback access on the necessary ports?0
-
Did you put the IP address before the hostname? The following is the correct way to redirect mysql.example.org back the the local machine in /etc/hosts:
127.0.0.1 mysql.example.org
0 -
Hi,
I have to apologize. I figured out a few days ago how to redirect the mysql server and forgot to post it here.
It works exactly as jabirali wrote:127.0.0.1 mysql.example.org
But it seems that this does not work, when I establish a VPN connection to my university network. But I have to double check this first and it is not a really problem for me, because I nearly never connect to the university and use than the mysql server.
Thanks a lot for your help and sorry again for forgetting to post my solution.
Best regards,
Michael0
Categories
- All Categories
- 176 LFX Mentorship
- 176 LFX Mentorship: Linux Kernel
- 750 Linux Foundation IT Professional Programs
- 373 Cloud Engineer IT Professional Program
- 169 Advanced Cloud Engineer IT Professional Program
- 74 DevOps IT Professional Program - Discontinued
- 4 DevOps & GitOps IT Professional Program
- 99 Cloud Native Developer IT Professional Program
- 7.6K Training Courses & Learning Paths
- 1 AI & ML Training
- 1 Blockchain & Decentralized Identity Training
- 3 Cloud & Containers Training
- 1 Cybersecurity Training
- 1 DevOps & Site-Reliability Training
- 1 Linux Kernel Development Training
- 1 Networking Training
- 1 Open Source Best Practice Training
- 1 System Administration Training
- 1 System Engineering Training
- 1 Web & Application Development Training
- 792 Hardware
- 202 Drivers
- 68 I/O Devices
- 37 Monitors
- 95 Multimedia
- 173 Networking
- 91 Printers & Scanners
- 87 Storage
- 768 Linux Distributions
- 81 Debian
- 67 Fedora
- 22 Linux Mint
- 13 Mageia
- 24 openSUSE
- 150 Red Hat Enterprise
- 31 Slackware
- 13 SUSE Enterprise
- 356 Ubuntu
- 465 Linux System Administration
- 31 Cloud Computing
- 73 Command Line/Scripting
- Github systems admin projects
- 98 Linux Security
- 78 Network Management
- 101 System Management
- 46 Web Management
- 106 Mobile Computing
- 18 Android
- 73 Development
- 1.2K New to Linux
- 1K Getting Started with Linux
- 392 Off Topic
- 121 Introductions
- 181 Small Talk
- 29 Study Material
- 946 Programming and Development
- 310 Kernel Development
- 618 Software Development
- 981 Software
- 373 Applications
- 182 Command Line
- 5 Compiling/Installing
- 68 Games
- 317 Installation
- Archived
- 2 LFD140 Class Forum
Upcoming Training
-
August 20, 2018
Kubernetes Administration (LFS458)
-
August 20, 2018
Linux System Administration (LFS301)
-
August 27, 2018
Open Source Virtualization (LFS462)
-
August 27, 2018
Linux Kernel Debugging and Security (LFD440)