Thursday, March 26, 2015

Reset MySQL root password



In some circumstances you need to reset MySQL root without knowing current password of it. For example you forget the password. You can change the password of the root user easily. The following guide is tested on Ubuntu 12.04 based on MySQL 5.5.

Reset root password (without knowing the current password)

To do so, please follow the instructions below:

Step 1: Stop the MySQL Service

At first, you need to stop the MySQL service:
$ sudo /etc/init.d/mysql stop

Step 2: Start the MySQL daemon in safe mode with skipping grants

Please run the MySQL in safe mode with skipping grants parameter:
$ sudo mysqld_safe --skip-grant-tables &

Step 3: run the MySQL prompt as root user without password

Now, you can enter the MySQL command line as root user without password:
$ mysql -u root

Step 4: Update the password of root user

Run the following commands to update root user password. Please replace "NEW-ROOT-PASSWORD" with the desired password:
mysql> use mysql;
mysql> update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
mysql> flush privileges;
mysql> quit

Step 5: Restart the MySQL service

You should restart the MySQL service to check the new password:
$ sudo /etc/init.d/mysql stop
$ sudo /etc/init.d/mysql start

Step 6: Login with the new password

Now, login to the MySQL prompt with the new password:
$ mysql -u root -p

Saturday, February 7, 2015

MySQL and Java workshop

Saeid Zebardast at workshop
Me at workshop


A few weeks ago, there was a Ubuntu 14.10 release party in Tehran, Iran. I had a workshop about developing software with MySQL and Java. Nearly 70 people were attended.
The workshop had three part:
  1. MySQL for beginners
  2. Java for beginners
  3. Developing software with MySQL and Java
Also, I create cheat sheets for Java and MySQL for participants.  I'm going to publish the presentations and cheat sheets in this post.

MySQL for beginners

The agenda for this presentation is:
  • Introduction
  • Installation
  • Execute SQL Statements
  • SQL Language
  • Some of The Most Important SQL Commands
  • SQL Syntax
  • Data Types
  • Operators
  • Some exercises

Java for beginners

The agenda for this presentation is:
  • Introduction
  • JVM
  • Java Principles
  • Java History
  • Java Uses
  • Installation
  • Java Syntax
  • Data Types
  • Variables
  • Operators
  • Select Statements
  • Iteration Statements
  • Comments Syntax
  • Access modifiers
  • Methods
  • Classes
  • Inheritance
  • Interfaces
  • Abstract
  • Java File Structure
  • Simple exercise

Developing software with MySQL and Java

The agenda for this presentation is:

  • Requirements
  • MySQL Data Definition
  • Java Classes
  • Methods for PhonebookApp
  • Compile and Run

MySQL Cheat Sheet

Java Cheat Sheet


Saeid Zebardast - MySQL and Java workshop
Saeid Zebardast - MySQL and Java workshop

MySQL and Java workshop
MySQL and Java workshop

Saeid Zebardast - MySQL and Java workshop
Saeid Zebardast - MySQL and Java workshop

MySQL and Java workshop
MySQL and Java workshop

Ubuntu 14.10 Release Party
Ubuntu 14.10 Release Party

Wednesday, October 22, 2014

How to auto-load MySQL on startup on OSX 10.10 (Yosemite)

After upgrading to OSX Yosemite(10.10), MySQL stopped loading on startup.
The MySQL documentation says:
The Startup Item installation adds a variable MYSQLCOM=-YES- to the system configuration file /etc/hostconfig. If you want to disable the automatic startup of MySQL, change this variable to MYSQLCOM=-NO-.

So, I opened that file and it says:
# This file is going away

As OSX mentioned this file is going away.

You need to create a Property List file (.plist) to start MySQL automatically on system startup.
First, create a new property list file:
sudo vim /Library/LaunchDaemons/com.mysql.mysql.plist
Add the following lines to it:
<!--?xml version="1.0" encoding="UTF-8"?-->
<plist version="1.0">
    <true />
Then update permissions and add it to launchctl:
sudo chown root:wheel /Library/LaunchDaemons/com.mysql.mysql.plist
sudo chmod 644 /Library/LaunchDaemons/com.mysql.mysql.plist
sudo launchctl load -w /Library/LaunchDaemons/com.mysql.mysql.plist
That's it. Now the MySQL service will be started on OS X startup.

Monday, May 26, 2014

Ubuntu 14.04 release party in Tehran, Iran

Ubuntu 14.04 Release Party
There was a release party of the Ubuntu 14.04 in Tehran. It was a great opportunity to see those young geeks there all together. Workshops, presentations and open ideas were the three sections of the festival.
The workshops were about introducing Ubuntu 14.04 features, FOSS business models, programming (Python, Ruby) and embedded Linux. Unlike the previous festivals, many people take part in workshops. The FOSS business models workshop was the most interesting one. Seems people are very curious to learn how to make money in the FOSS territory.
Presenting the new features in Ubuntu 14.04 was the next part of the festival. Danial Behzadi made a perfect presentation. The other presentations were about GNU/Linux news, OpenStack, Using Linux Everywhere and Salam-Donya magazine.
The open idea was the last part of the festival. Five ideas were presented and the participants voted them. The winner got 5,000,000 rial. It was about a network grid computing solution.
Photos by Negar Najimi: