Mysql connection error

in

When trying to connect to my mysql database using greensql i get a connection error.

$this->connection_id=mysql_connect("localhost:3305", $this->user, $this->pass, 1) or $this->connection_error();

will connect to mysql, but greensql will not be 'watching'

$this->connection_id=mysql_connect("127.0.0.1:3305", $this->user, $this->pass, 1) or $this->connection_error();

gives this wonderful error(and $this->connection_error(); just outputs a nice msg to refresh to the user and stores the error in a log for me, the following is the log)

Warning: mysql_connect() [function.mysql-connect]: Lost connection to MySQL server during query in /home/knight/public_html/class/class_db_mysql.php on line 46
FATAL ERROR: Could not connect to database.

Comments

Hi Can you please print

Hi

Can you please print which mysql error u are getting.

You can get it using mysql_error() function:

$this->connection_id=mysql_connect("127.0.0.1:3305", $this->user, $this->pass, 1) or die('Could not connect: ' . mysql_error());

Warning: mysql_connect()

Warning: mysql_connect() [function.mysql-connect]: Lost connection to MySQL server during query in /home/knight/public_html/class/class_db_mysql.php on line 47
Lost connection to MySQL server during query

$this->connection_id=mysql_connect("127.0.0.1:3305", $this->user, $this->pass, 1) or die(mysql_error());

I thought about your issue

I thought about your issue and I think I know what is the problem.

You db user is allowed access from 'localhost' and not from '127.0.0.1', as a result MySQL blocks access to your database. In order to fix this, you need to explicitly add new user that can connect from '127.0.0.1'. In MySQL you can not specify additional host for existing user. It must be another one. If you wish, both old and new users could have the same names but different host.

You need to issue the following mysql command (run it as a root user):

mysql> GRANT SELECT,INSERT,UPDATE,DELETE PRIVILEGES ON YOUR_DB.* TO 'DB_USER'@'127.0.0.1' IDENTIFIED BY 'USER_PASSWORD';

Change YOUR_DB to the appropriate database name.
DB_USER is a new user name that will be used to access the database.
USER_PASSWORD new user password.

mysql> GRANT

mysql> GRANT SELECT,INSERT,UPDATE,DELETE PRIVILEGES ON knight.* TO 'knight.god'@'127.0.0.1' IDENTIFIED BY 'PASSWORD';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'PRIVILEGES ON knight.* TO 'knight.god'@'127.0.0.1' IDENTIFIED BY 'PASSWORD' at line 1

Ops, It must be: mysql>

Ops,

It must be:

mysql> GRANT SELECT,INSERT,UPDATE,DELETE ON knight.* TO 'knight.god'@'127.0.0.1' IDENTIFIED BY 'PASSWORD';

Thanks

mysql> GRANT

mysql> GRANT SELECT,INSERT,UPDATE,DELETE ON knight.* TO 'knight.god'@'127.0.0.1' IDENTIFIED BY 'XXXXXXX';
Query OK, 0 rows affected (0.04 sec)

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'knight_god'@'localhost' (using password: YES) in /home/knight/public_html/class/class_db_mysql.php on line 46
FATAL ERROR: Could not connect to database.

Please Just Refresh The Page

Again, change localhost to

Again, change localhost to 127.0.0.1.

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'knight_god'@'localhost' (using password: YES) in /home/knight/public_html/class/class_db_mysql.php on line 46
FATAL ERROR: Could not connect to database.

Back to top