Recover MySQL root Password

It is only common to forget the database password. However, we can recover MySQL database server password following five easy steps.

  1. First step is to stop the MySQL server process.
    $> sudo /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 the password.
    $> sudo mysqld_safe --skip-grant-tables &
  3. Then, connect to mysql server as the root user.
    $> mysql -u root
  4. Now that we’re in as the root user, setup new mysql root account password i.e. reset mysql password.
  5. mysql> use mysql;
    mysql> update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
    mysql> flush privileges;
    mysql> quit
  6. Finally, exit and restart the MySQL server.
    $> sudo /etc/init.d/mysql stop
    $> sudo /etc/init.d/mysql start
    $> mysql -u root -p

With this we would’ve successfully changed the password.
 

Advertisements

Easy Web Fonts with Google Font API

Web fonts allow you to step outside of the normal web-safe fonts by taking advantage of CSS’s @font-face rule. However, right now, browsers aren’t uniform in its implementation of @font-face. More specifically, web browsers differ in the types of font files they support (hopefully this will change with the WOFF standards). Additionally, you must be careful with the fonts you use since some of them might not be licensed for web use.

To sidestep the issues with @font-face, the Google Font API is here to the rescue. Here is an example of using the Cantarell font on elements that takes advantage of Google Fonts API. If you want to use the Cantarell font from Google Font API, first reference the remote stylesheet inside your tags:

href="http://fonts.googleapis.com/css?family=Cantarell"

To use the font in h1 elements, simply use the font-family CSS property.

h1 {
    font-family: 'Cantarell', Arial, serif; /*Use a font stack, just in case.*/
}

 

Loading data from multiple files in Ruby using Hash

Loading data into Database reading from multiple files was never easy. I have been working on different projects lately, which required such exercise often. A general technique I followed to do that is explained here. In a gist, this is what it looks like:

require 'rubygems'
require 'fastercsv'

files.each do |key, value|
	file = "#{RAILS_ROOT}/db/drugsatfda/" + key
	recs = 0

	puts "Working with #{value.pluralize}.."
	FasterCSV.foreach(file, :headers => true) do |row|
		begin
			obj = value.constantize.new(Array.to_hash(row.headers, row.fields))
			obj.save

			recs += 1
		rescue => e
			puts "Rows processed: " + recs.to_s
			puts e
		end
	end
	puts "Loaded #{recs} #{value.pluralize}"
end

What do you think?