Sep 29, 2008

reset mysql root password

Recently, one person left me in his system to solve one of his problem associated with webservice.
He left me and went somewhere and asked me to solve the problem before I left.

During this i requited the mysql root password, but he want there. So i googled to reset the mysql password. And here is what i did to reset the password.

$ sudo /etc/init.d/mysql stop

$ sudo mysqld_safe --skip-grant-tables --user=root

$ sudo mysql -u root

Run this query in mysql prompt:
mysql> UPDATE mysql.user SET Password=PASSWORD('newpassword') WHERE User='root';

Finally kill this mysql process and restart it safely:

$ sudo /etc/init.d/mysql start


Sep 28, 2008

solve "com.mysql.jdbc.CommunicationsException"

This is the error that I got when trying to connect to mysql (of lampp package, yes in linux) using Hibernate in java.

WARN 2008-09-28 13:55:17,116 org.hibernate.cfg.SettingsFactory -s Could not obtain connection metadata
com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:

MESSAGE: Connection refused

STACKTRACE: Connection refused
at Method)
at com.mysql.jdbc.StandardSocketFactory.connect(
at com.mysql.jdbc.MysqlIO.(

Basically, the problem here is because of jdbc connector, which was unable to connect to the database. There are two ways of communication with mysql in linux.
  1. Don't listen on a TCP/IP port at all, if all processes that need to connect to mysqld run on the same host. There interaction with mysqld are made via Unix sockets or named pipes which is .sock file.

  2. B. Simply listen on a TCP/IP port. This allows remote communication to the database too.

Lampp initial configuration sets the first method of communication. And the sock file is created in < lampp root dir >/var/mysql/mysql.sock . But by default the jdbc search it in "/var/run/mysql/mysql.sock" (somewhere like this). Due to this problem, jdbc wont be able to connect to the database.

There are many ways to solve this:
The simple one is to switch to second type of communication method.
find the following line in <lampp root dir >/etc/my.cnf

and comment it.
# skip-networking

Hope this helps you out.