Solved

How do I configure my server to use "db1.webaddress.com" instead of "localhost"

Posted on 2007-11-19
19
280 Views
Last Modified: 2013-12-16
How do I configure mysql to be accessed from a web address instead of only from localhost?
0
Comment
Question by:amakaram
  • 8
  • 4
  • 3
  • +1
19 Comments
 
LVL 15

Expert Comment

by:babuno5
ID: 20311625
add an entry in
if linux
/etc/hosts
or for windows
C:\WINDOWS\system32\drivers\etc\hosts


Just add an entry there

127.0.0.1 db1.webaddress.com
0
 

Author Comment

by:amakaram
ID: 20311650
127.0.0.1 being my server ip address?  

Does it matter what "db1" is?



0
 
LVL 15

Expert Comment

by:babuno5
ID: 20311656
127.0.0.1 being my server ip address?  
172.0.0.1 means the same machine where you are accessing it

Does it matter what "db1" is?
No if you using only localhost
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

by:amakaram
ID: 20311663
Sounds good, will try and advise.
0
 
LVL 14

Expert Comment

by:ygoutham
ID: 20312034
you dont do it that way

you use the grant command on mysql command prompt to grant the rights to all users from different hosts

GRANT ALL ON database_name.* to "user"@"%" identified by password "secret";

this adds an entry in the mysql.users table with the appropriate rights and then if you do

netstat -an | grep 3306

you would see that the server is listening on all the interfaces (including the static ip address) which can be used by any other program to access the mysql tables from a remote location.
0
 

Author Comment

by:amakaram
ID: 20312098
oh, I'm not looking to use "db1.webaddress.com" instead of "localhost" on the same server, I'm looking to connect to this server's mysql from another server.

Content in my "hosts" file:

127.0.0.1  GXXXXHOST.prod.phx1.sXXXXXr.net GXXXXHOST localhost localhost.localdomain db1.gXXXXhost.com

I added the db1... at the end of that same line.

Got this error:
Warning: mysql_connect(): Unknown MySQL server host 'db1.gXXXXhost.com' (1) in /home/content/XXXX/html/testing/connect.php on line 9
Could not connect: Unknown MySQL server host 'db1.gXXXXhost.com' (1)

Any thoughts?
0
 

Author Comment

by:amakaram
ID: 20312296
ygoutham:

Im willing to give that a try, however, I do need a little more detail.

Im not sure where the mysql command prompt is.

I have putty open and I am connected to the server from there.  Am I in the right location?
0
 

Author Comment

by:amakaram
ID: 20315354
babuno5:

That has not yelded any success.

I have run a short scipt from another server and cannot connect.
0
 
LVL 14

Expert Comment

by:ygoutham
ID: 20317818
when you are in the putty screen on the command prompt do a

mysql -u root -p

that should take you to mysql command prompt which looks like

mysql>

from where you can run the grant command
0
 
LVL 15

Expert Comment

by:babuno5
ID: 20317928
yes as i had mentioned it will work only on localhost

>>I have run a short scipt from another server and cannot connect.

But from another server it will not work

If you want to connect from outside then you need to buy a domain name that points to that server  and follow what @ygoutham said in his earlier post
0
 

Author Comment

by:amakaram
ID: 20537310
Sorry for the delay, but would like to follow up with this now that I have some time again.

ygoutham:

Lets just make sure Im following you here.

If my server A url is "http://www.webaddress.com", static ip of 166.123.456.789
which has a mysql database called "thedatabase123"
and accessible through myphpadmin with credentials of "theuser456", "thepass789",
and want to create: "db1.webaddress.com",
accessible from Server B, "http://www.anyotherdomain.com" (or any other server)...

I log onto the server, type "mysql -u root -p" which gives me "mysql>".

I then type exactly this (with quotes etc):

GRANT ALL ON thedatabase123.* to "theuser456"@"%" identified by password "thepass789";

Then I can go to Server B and create a php file with this:
$db = mysql_connect("db1.webaddress.com", "theuser456", "thepass789");
or
$db = mysql_connect("166.123.456.789", "theuser456", "thepass789");

Is this correct?

Thanks again.
0
 
LVL 14

Accepted Solution

by:
ygoutham earned 500 total points
ID: 20539780
that is completely correct

however, if for some reason it would not work then you can always add the IP address of the machine B that you are trying to access it from.  

GRANT ALL ON thedatabase123.* to "theuser456"@"SERVER_B.IP.ADDRESS.HERE" identified by password "thepass789";

also see that mysql port is open and listening on all interfaces

netstat -an | grep 3306

should show that it is listening on

tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN

if you get 127.0.0.1:3306 then it means that the daemon is listening only on the localhost and not for external client machines
0
 

Author Comment

by:amakaram
ID: 20544302
Hey guys,

Ok, I logged onto that hosting account (/bin/bash) and the server root and server root with su in these examples, none with success.

[ONE]
using "root" would not allow me access in any of the server logins

[TWO]
using the user name as in "theuser456@localhost", I was able to get to MYSQL>
[THREE]
...but tried both the examples with, and without "%" both with access denied.

Any ideas?
(ONE)
mysql -u root -p
ERROR 1045: Access denied for user: 'root@localhost' (Using password: YES)
----------------------
(TWO)
mysql -u theuser456 -p
 
mysql> GRANT ALL ON thedatabase123.* to "theuser456"@"%" identified by password "thepass789";
ERROR 1044: Access denied for user: 'theuser456@localhost' to database 'thedatabase123'
 
(THREE)
mysql> GRANT ALL ON thedatabase123.* to "theuser456"@"XX.XXX.XX.XX" identified by password "thepass789";
ERROR 1044: Access denied for user: 'theuser456@localhost' to database 'thedatabase123'
mysql>

Open in new window

0
 
LVL 14

Expert Comment

by:ygoutham
ID: 20546825
obviously the user "theuser456" is not permitted to give rights to himself using this way.  you need to have root access to be granting rights to any of the other users.  have you forgotten the root password

then do the following to change the root password

http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html


0
 

Author Comment

by:amakaram
ID: 20714080
This is not abandoned. I'm trying to gain access. Just really busy with other work.  Sorry for the delay.
0
 
LVL 1

Expert Comment

by:Computer101
ID: 21133314
Forced accept.

Computer101
EE Admin
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Determining creation & modification dates on MySQL tables 4 41
Red Hat 7 Linux on Azure cannot run a command as root 22 43
bash file 10 37
linux SFTP 8 46
As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question