Wednesday, July 11, 2012

MySQL Error number 2003?



I'm always getting Error 2003 when connecting to my newly set mysql database on a different server. 


I found out the solution to this problem from Ubnuntu forums: 

The default from mysql server is to be binding to localhost (127.0.0.1), this means it will only accept connections from local applications. 


To change that:


edit /etc/mysql/my.cnf and comment out the line bind-address = 127.0.0.1: 


Then you will need to restart the mysql server with: 


/etc/init.d/mysql restart 


That solved the problem. 

How to Change Mysql root password


MySQL Change root Password


There are 2 ways for doing this: 

1. Using mysqladmin
2. Updating using mysql database commands

Using mysqladmin

To setup root password for first time, use mysqladmin command at shell prompt as: 

$ mysqladmin -u root password NEWPASSWORD

If there was an old password already set for e.g., oldpwd, you can change it to a new one by following command:

$ mysqladmin -u root -p'oldpwd' password 'newpwd'

Using mysql database shell commands

mysql stores all user information into a user table inside Mysql database. You can directly update the password for a user in this database table. All you need to do is login to the database and fire below command: 

mysql> update user set password=PASSWORD("newpwd") where User='root';
mysql> flush privileges;
mysql> quit

How to Allow MySQL Client to Connect to Remote MySQL server

I started getting an error ERROR 1130: Host is not allowed to connect to this MySQL server” when I was trying to connect to a new mysql server which i had recently setup somewhere else instead of my own local machine. 


After a lot of troubleshooting and reading I found that by default, MySQL does not allow remote clients to connect to the MySQL database. And that was preventing my local machine to connect to this remove server which I have setup. 


To actually verify if your local machine is allowed or not you can use the simply telnet command as shown below: 


telnet my-sql-server-hostname 3306


If your local machine is not allowed to connect to this mysql host then you will get an error such as: 



$ telnet my-sql-server-hostname 3306host 192.168.1.3 is not allowed to connect to this mysql server
$ mysql -u root -p
Enter password:
mysql> use mysql
mysql> GRANT ALL ON *.* to root@'192.168.1.3' IDENTIFIED BY 'mysql-password';
mysql> FLUSH PRIVILEGES;




If you want to allow a specific client ip-address (for example: 192.168.1.3) to access the mysql database running on a server, you should execute the following command on the server that is running the mysql database.



Also, update firewall rules to make sure port# 3306 is open on the server that is running the mysql database.
After the above changes, when you try to connect to the mysql database from a remote client, you’ll not get the “Host is not allowed to connect to this MySQL server” error message anymore.

Getting error java.lang.ClassNotFoundException: com.mysql.jdbc.Driver.

My WebService used to work great on my development machine but when I moved it to production after creating a war file of it, I started receiving this error 


java.lang.ClassNotFoundException: com.mysql.jdbc.Driver


After debugging, i figured that the dependent mysql jar were not exported to WEB-INF/lib. After copying it to /lib it started working correctly.