Thursday, April 22, 2010

Recover MySQL root Password

You can recover MySQL database server's root password with the following five steps.
  1. Stop the MySQL server process: $ /etc/init.d/mysql stop
  2. Start the MySQL (mysqld) server/daemon process with the --skip-grant-tables option so that it will not prompt for password: $ mysqld_safe --skip-grant-tables &
  3. Connect to mysql server as the root user: $ mysql -u root
  4. Setup new mysql root account password and quit: mysql> use mysql;
    mysql> update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
    mysql> flush privileges;
    mysql> quit
  5. Restart the MySQL server: $ /etc/init.d/mysql stop

Monday, April 5, 2010

Make data or tmp web-writable

In a web application, we need to make data or tmp directory writable by the web server. I saw many people achieve this by changing the permission level of that directory recursively to 777 in Unix/Linux:

$ chmod -R 777 tmp


$ chmod -R 777 data

This is really unnecessary. You can find out on behalf of which user, your web server is running by running this single line of php code:

echo `whoami`;

In my case, i got 'daemon' as the user on behalf of which the webserver is running.
Now we need to change the ownership of the data or tmp directory and make 'daemon' as the owner.

$chown -R daemon tmp