Search code examples
mysqlzend-frameworkzend-db

cant connect to MySQL server


Fawad-PC = my pc name (windows) i deleted my mysql server coz i install xampp too there were 2 same databases with me. so when ever i try to login to my app its connecting to the 1 in mysql server and not in xampp one so i un install mysql server but the process was too slow and cant terminate so i restart my windows after that i check programs and features and mysql server were not there so i came to my app and when i try 2 login i got this wiered error

Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [1130] Host 'Fawad-PC' is
not allowed to connect to this MySQL server' in D:\SVN data\WebClient_PHP\trunk\library
\Zend\Db\Adapter\Pdo\Abstract.php:129 

can any one tell what is this error.my app was running very nice but today i dont know how when i enter my password its showing this error

  Stack trace:

 #0 D:\SVN data\Phoggi_WebClient_PHP\trunk\phoggi\library\Zend\Db\Adapter
\Pdo\Abstract.php(129): PDO->__construct('mysql:host=192....', 'root', 'root', Array) 

#1 D:\SVN data\Phoggi_WebClient_PHP\trunk\phoggi\library\Zend\Db\Adapter\Pdo\Mysql.php 
(109): Zend_Db_Adapter_Pdo_Abstract->_connect()

#2 D:\SVN data\Phoggi_WebClient_PHP\trunk\phoggi\library\Zend\Db\Adapter\Abstract.php
(860): Zend_Db_Adapter_Pdo_Mysql->_connect()

#3 D:\SVN data\Phoggi_WebClient_PHP\trunk\phoggi\library\Zend\Db\Adapter\Abstract.php
(930): Zend_Db_Adapter_Abstract->quote('123', NULL) 

 #4 D:\SVN data\Phoggi_WebClient_PHP\trunk\phoggi\library\Zend\Auth\Adapter\DbTable.php
(449): Zend_Db_Adapter_Abstract->quoteInto('`user_password`...', '123') #5 D:\SVN data 
\Phoggi_WebClient_PHP\trunk\phoggi\library\Zend\Aut in D:\SVN data\Phoggi_WebClient_PHP
 \trunk\phoggi\library\Zend\Db\Adapter\Pdo\Abstract.php on line 144

Solution

  • From the small piece of the connection string visible in the stack trace, I see the mysql server host is an IP address.

    If this newly installed MySQL server is on the same PC that is running Apache, then try changing the host to localhost instead of the IP address.

    If you are trying to connect to a MySQL server on another PC, then you will have to add a user that is allowed to connect from a remote host.

    Examples:

    CREATE USER 'user'@'Fawad-PC' IDENTIFIED BY 'password';  // can connect from Fawad-PC
    

    or

    CREATE USER 'user'@'%' IDENTIFIED BY 'password';  // can connect from ANYWHERE
    

    Then you will have to grant privileges on a specific database to that user:

    GRANT ALL on database.* to 'user'@'Fawad-PC'
    

    Try changing the MySQL host to localhost first though, I think that will solve your problem.