How to get PHP and MySQL to play nice

MySQL
2010-03-10
2013-06-05
  • Mafaz Mazeen

    Mafaz Mazeen - 2010-03-10

    Hi all. Can't seem to get PHP to play nice with MySQL.

    First I logged into MySQL, created the db, switched to it and then
    granted (what I thought were) correct privileges:


    Macintosh-7:~ jason$ /usr/local/mysql/bin/mysql -u root
    mysql> create database wes;
    Query OK, 1 row affected (0.00 sec)
    mysql> use wes
    Database changed
    mysql> grant all privileges on wes.* to user@localhost identified by
    'changeme'
    -> ;
    Query OK, 0 rows affected (0.08 sec)


    I then created a bit of PHP to test this…

    <?php
    $dbhost = 'localhost';
    $dbuser = 'user';
    $dbpass = 'changeme';
    $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error
    connecting to mysql');
    ?>


    But when I access that PHP page, I get:
    Warning: mysql_connect() : Can't connect to
    local MySQL server through socket '/var/mysql/mysql.sock' (2) in /
    Library/WebServer/Documents/wes/mysql_test.php on line 7
    Error connecting to mysql
    Any thoughts on what I'm doing wrong? I have checked to make sure
    Apache and PHP are running. I can access scripts through localhost
    just fine, the problem is only with MySQL.
    Thanks much in advance,
    Jason

     
  • Arnold De Souza

    Arnold De Souza - 2010-08-02

    Hi,

    Try to run this query for database..
    GRANT USAGE ON * . * TO 'user'@'localhost' IDENTIFIED BY 'password' WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ;

    Regards,
    Dulitha

     
  • Arnold De Souza

    Arnold De Souza - 2010-09-15

    thanks for your nice help.

     
  • Arnold De Souza

    Arnold De Souza - 2010-11-10

    When I access that PHP page, I get:
    Warning: mysql_connect() : Can't connect to
    local MySQL server through socket '/var/mysql/mysql.sock' (2) in /
    Library/WebServer/Documents/wes/mysql_test.php on line 7
    Error connecting to mysql

    This is a common error when the mysql daemon isn't running, check that
    it's still running and the socket file is created in /var/mysql direcotry.

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks