How to create a MySQL server with a domain as hostname? - mysql

I'm creating a MySQL cluster and I want to use port 3306 for all of the MySQL instances and the only way I can think of to do that on one ip is to create a domain as hostname, but I can't figure out how o can add a domain as hostname.
Hope you can help.
Thanks
EDIT::
Expected result:
Able to connect to 2 MySQL Instances on a single network with one IP:
Network A: (ip: 8.8.8.8)
Instance 1: db1.example.com PORT 3306
Intance 2: db2.example.com PORT 3306
Network B: (ip: 8.8.8.9)
Instance 3: db3.example.com PORT 3306
Intance 4: db4.example.com PORT 3306

Web browsers present the Host header to web servers. A server, when it sees an incoming http or https request, uses that header to route the request to one of multiple web sites it's hosting.
For example, you can have the hostnames www.example.com and www.example.org both resolve to the IP address 10.254.253.252. Then when a browser makes a request to http://www.example.org , it will arrive at the server with the header Host: www.example.org.
But. the MySQL protocol doesn't have the equivalent of the Host header. Therefore, you can't do what you hope to do.

Related

Is there a way to "mask" an smtp server?

I am using a service for smtp relay and they give me a smtp server url (mail.theirdomain).. I wanted to ask if there is any way of "masking" this for example with some dns records to make the mail.theirdomain, mail.mydomain?
Sure, you can do a DNS lookup of mail.theirdomain.com and see what IP address this hostname points to (e.g. x.x.x.x). Then, you can create a hostname mail.mydomain.com, and point this hostname to the same IP address (x.x.x.x).
But, if you do a reverse DNS lookup (i.e. PTR lookup) of x.x.x.x, it will likely point to mail.theirdomain.com (not mail.mydomain.com), and you can't change this, because you do not have control of x.x.x.x.
Also, if you open an SMTP connection to mail.mydomain.com, it will likely show mail.theirdomain.com in the SMTP banner that the server responds with after a client connects - and this is not something that you can change either.

MXRecord error when running diagnostics on hMailServer

I have downloaded and installed hmailserver. I want to run it on my local machine and want to send email using a local web application which is also running on my local machine. My web application couldn't send email (got error - couldn't connect to mydomain:25) and thus I thought to first run hmailserver's diagnostic tool to test things.
But when I run diagnostics on it, I see the error:
Test: Collect server details
hMailServer version: hMailServer 5.6.7-B2425
Database type: MSSQL Compact
Test: Test IPv6
IPv6 support is available in operating system.
Test: Test outbound port
SMTP relayer not in use. Attempting mail.hmailserver.com:25...
Trying to connect to host mail.hmailserver.com...
Trying to connect to TCP/IP address 5.189.183.138 on port 25.
Received: 220 mail.hmailserver.com ESMTP.
Connected successfully.
Test: Test backup directory
ERROR: Backup directory has not been specified.
Test: Test MX records
Trying to resolve MX records for mydomain.com...
ERROR: MX records for domain mydomain.com could not be resolved
Test: Test local connect
Connecting to TCP/IP address in MX records for local domain domain mydomain.com...
ERROR: MX records for local domain mydomain.com could not be resolved
Test: Test message file locations
Relative message paths are stored in the database for all messages.
Test: Test IP range configuration
No problems were found in the IP range configuration.
To be honest, I don't know what MX Record is and how to set it up. Things I have done so far are:
Installed hmailserver (obviously!)
Added a domain (mydomain.com)
Added an account in mydomain.com (signup#mydomain.com)
In settings->Protocols ->SMTP, I added localhost in Delivery of email ->Localhostname section
In c:\Windows\System32\Drivers\etc\hosts file, I added entry 127.0.0.1 mydomain.com #for play application
When I run netstat -a, I see that hmailserver is listening on port 25 (I tested it using net stop hmailserver and net start hmailserver)
Proto Local Address Foreign Address State
TCP 0.0.0.0:25 DESKTOP-6PLQOLJ:0 LISTENING[/list]
Have I made a mistake?
This Error Message is shown if your Windows Operating system DNS-Resolver Service points to an DNS-Server which doesn't know anything or cannot forward the Query to the DNS-Server in charge for the specified Domain and its MX-Record.
In short terms: Without having your DNS-Domain correctly configured, hMailServer (or any other SMTP-Server) can't work.

Unable to connect to Mysql from Django app - AWS, EC2, RDS

I am having trouble connecting to my RDS MySQL Database.
My current Set up:
Django 1.9+
AWS - Launched an EC2 Instance (Amazon Linux). Launched an RDS instance of MySQL (5.6.7). I created a Virtual PC (VPC) for the EC2 instance and RDS instance, and in that group created several security rules so the EC2 instance could connect to the MySQL RDS. Below are the security rules I use and associate with the VPC.
Inbound Rules: (Type, Protocol, Port Range, Source)
1. Http , TCP, 80 , 0.0.0.0/0
2. SSH , TCP, 22 , <homePC address>/32
3. HTTPS, TCP, 443, 0.0.0.0/0
4. MYSQL/Aurora, TCP, 3306, source (my created security group)
Nginx - Serving my content redirecting from port 80 to port 443. I created SSL certificates in order to make my site secure. I correctly served my Django application, and the static files. Nginx serves everything great!
Previously I was able to connect to my RDS instance. I did not set up an elastic IP at that point in time, as it took some time to transfer my domain over to Route53 (amazons DNS). I successfully was able to transfer it, and associate it with my EC2 instance and even start my application
The problems -
First Problem I cannot connect to the RDS from my EC2 instance. I have checked my django settings file and the secret file (the one that feeds my settings file with sensitive information which I keep out of version control). Here are examples of my settings for the mysql connection - I changed them obviously
"DATABASE_NAME":"myDatabase",
"DATABASE_USERNAME": "myUsername",
"DATABASE_PASSWORD": "myPassword123",
I double checked the username and password in the RDS console, and even reset the password.
After I went ahead and activated my virtual environment and attempted to connect.
python manage.py dbshell
My Error was
ERROR 1045 (28000): Access denied for user 'myUsername'#'<private IP address from Elastic IP>' (using password: YES)
Notive the user name is not what I utilized in the settings. It changed. I feel this is the root cause of the problem, but am unsure why Django would change my username in such a manner.
Second Problem - I also try to connect to the database directly using mysql. I double check my endpoint, username and password are correct, but also run into trouble connecting.
Note - As I said, I was able to connect in both manners listed above before acquiring my IP address. Thus my troubles are configuring security rules to allow a permanent IP address, and being unable to use TCP connect to use the Mysql client to log in.
Thanks in advance.

sqldeveloper and cpanel

i can't access my website mysql db from sqldeveloper.
in cpanel there is an option (Remote Database Access Hosts) which allows one to add IP addresses that can access the db. I have entered my ip address and i have used the % wildcard.
so for instance if my ip address was 12.34.56.78, i have entered my ip address as:
1 - 12.34.56.78
2 - 12.34.56.%
3 - 12.%.%.%
in sqldeveloper i have downloaded and added the mysql third party jdbc driver .jar file (mysql-connector-java-5.1.13-bin.jar).
i have the right user name, password, hostname and port.
so, if my website domain was called www.mysite.com and my username was user, the username i would use in sqldeveloper would be mysite_user.
and the hostname would be www.mysite.com.
the port i am told via cpanel is 3307.
i bow to any superior knowledge if my assumptions are incorrect.
any help would be appreciated
-- edit --
oh yeah, the error message I get (pretty important!) in sqldeveloper is
Status : Failure - Test failed: Communications link failureThe last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
-- end edit --
I do the same via cPanel but after i connect to my host via SqlYog community edition...
Uniqe differce is the port, i use the standard 3306 port instead a custom port.
Try if it connect: http://code.google.com/p/sqlyog/
It turns out that i did need to use port 3306 but more importantly, my web host needed to make a change on their firewall.
i managed to connect using mysite.com, username, password and port 3306.
thanks #Achilleterzo for your help in the meantime

Under what scenarios would one want to connect to a host other than localhost?

Under what scenarios would one want to connect to a host other than localhost? What I mean is when:
mysql_connect('localhost', 'root', 'root');
I provide 'localhost' as the first argument without ever stopping to think what purpose it serves. I guess the opposite would be remote host, but when would you actually use it?
localhost is a hostname that refers to the local machine.
Therefore, you pass that to connect to a server running on the local machine.
If you want to connect to a MySQL server running on a different machine, you would pass that machine's domain name or IP address instead of localhost
.
It depends where the SQL server is living. In an application architecture you could potentially have UI, Services, and SQL living on separate boxes. In this scenario you'd point mysql_connect() to the appropriate machine.
localhost is simply an alias for the computer that you are running the script on. By connecting to localhost, you are connecting to a server on the same computer.
Replacing 'localhost' with an IP or host name allows you to connect to a different computer.