Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2015
    Posts
    2

    Unanswered: Connecting to MySQL DB in linux

    Hi

    We have MySQL DB in linux server (hosted as virtual machine) we will be using putty to connect it.

    We have the PHP code in windows 7 machine.

    Both are in our local net work. When trying to connect to DB using PHP code the below error occurs. Please suggest.
    No connection could be made because the target machine actively refused it.

    Code used
    <?php
    $dbuser="root";
    $dbpass="PW";
    $dbname="DB";
    $dbhost="xxx.xxx.x.xx";

    $conn = mysql_connect($dbhost, $dbuser, $dbpass);
    if(! $conn )
    {
    die('Could not connect: ' . mysql_error());
    }
    mysql_select_db($dbname);
    ?>
    Last edited by shanthini; 02-23-15 at 02:09.

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    My initial guess would be the computer hosting the server is blocking attempts to connect to MySQL
    that is almost certainly a firewall issue... check that the port you are using for MySQL is open. the default MySQL socket is 3306

    of course it could be that your computer hasn't got an active MySQL server running (de facto if the server isn't working the the host will refuse a connection attempt on 3306). what steps have you taken to prove the server is awake and is accepting connections. If needs be do it as a two stage process. First off on the computer hosting the server prove its awake, then repeat the process on other remote computers. Again I find Workbench very useful for these sort of issues.
    When conducting a seance to find out if a server is awake its usefull to use the system admin user account and password, but only till you have proved the system is alive and well

    I don't think its a permissions issue at present, but check permissions on the machine hosting the server
    make certain that your user, password and access permissions are set.
    Ive always found setting permissions in MySQL a faff. I usually GRANT the required permissions to a specific IP address for a specific IP address or all IP addresses. Ive always struggled GRANTing on a IP range.

    How are you GRANTing the permissions?
    are you using a SQL query as admin
    are you doing thins from the command line (is it MySQLD?)
    or are you using MySQL Workbench?

    if you've done it via the command line, and or a SQL query you may well have to FLUSH PRIVILEGES after doing that, Im pretty certain Workbench does that for you.
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Feb 2015
    Posts
    2

    Connecting to MySQL DB in linux

    Thanks you for the reply

    Click image for larger version. 

Name:	Ref_23022015.jpg 
Views:	1 
Size:	58.6 KB 
ID:	16187

    Please refer attached screen shot for the privileges given. I also did FLUSH PRIVILEGES

    Still the same error appears.

    Please suggest

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    see post #2
    My initial guess would be the computer hosting the server is blocking attempts to connect to MySQL
    that is almost certainly a firewall issue... check that the port you are using for MySQL is open. the default MySQL socket is 3306

    of course it could be that your computer hasn't got an active MySQL server running (de facto if the server isn't working the the host will refuse a connection attempt on 3306). what steps have you taken to prove the server is awake and is accepting connections. If needs be do it as a two stage process. First off on the computer hosting the server prove its awake, then repeat the process on other remote computers. Again I find Workbench very useful for these sort of issues.
    When conducting a seance to find out if a server is awake its usefull to use the system admin user account and password, but only till you have proved the system is alive and well

    I don't think its a permissions issue at present,
    so what steps have you take to prove the server is visible across any firewall
    on the face of it the server is active

    because the computer is refusing the cinnection it sounds tome like a frewall issue NOT a server issue.
    but to abstract the problem run workbench on the server hosting the db
    and then again workstation you are not connecting from

    MySQL secruity can be a little problemtical to set up, or at least it is for me, but Im not a MySQL (or any other form of DBA)

    what I have found over the years is to explictly specify the IP address of a remote computer untill such time as you have proven the lkink between the server and any clients accessing the db.

    bear in mind your source of problems are legion

    it could be the db server isn't talking tot he the we sperver
    it could be the PHP installation is banjaxed
    take it a step at a time prove that you have connectivity and them move onto another area, changing just the one thing
    workbecnh is MySQL's preferred adminstration tool
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •