Tuesday, January 18, 2011

How To Install and run MySQL

How to install and run the MySQL

Step to install and work on the MySQL Server

Step 1 : Download the MYSQL

Download the MySQL and install the MySQL into C:\mysql.
Extract the ZIP to your C: drive and rename the folder from “mysql- x.x.xx-win32″ to “mysql”. MySQL can be installed anywhere on your

Step 2 : Move the data folder(optional)

I recommend placing the data folder on another drive or
partition to make backups and re-installation easier. For the
purposes of this example, we will create a folder called
D:\MySQLdata and move the contents of C:\mysql\data into it.

You should now have two folders, D:\MySQLdata\mysql and
D:\MySQLdata\test. The original C:\mysql\data folder can be

Step 3 : Create the configuration file

MySQL provides several configuration methods but, in general, it
is easiest to to create a my.ini file in the mysql folder. There
are hundreds of options to tweak MySQL to your exact

but the simplest my.ini file is:

# installation directory
# data directory

Step 4 : Test your MySQL Server

Open the command prompt and run the following command

This will start the MySQL server which listens for requests on
localhost port 3306.
Open another command window and run the following command

cd c:\mysql\bin
mysql –u root

This will show a welcome message and the mysql> prompt.
Enter “show databases;” to view a list of the pre-defined

Step 5: Change the root password

The MySQL root user is an all-powerful account that can create and
destroy databases. If you are on a shared network, it is advisable
to change the default (blank) password. From the mysql> prompt,

UPDATE mysql.user SET password=PASSWORD("my-new-password") WHERE


You will be prompted for the password the next time you start the
MySQL command line.

Enter “exit” at the mysql> prompt to stop the command line client.
You should now shut down MySQL with the following command:

Step 6 : Create Table in database velsDB

First we need to Create a database :

mysql> create database velsDB ;
mysql>use database velsDB;

create table resource_vacation_plan(
employee_id varchar(36) not null,
employee_name varchar(32) not null,
start_date date,
end_date date,
no_of_days integer(3)


If you are going to use my sql in your code the use the following
to create the DB connection:

String DB_MYSQL_DRIVER_NAME = "com.mysql.jdbc.Driver";
String DB_URL_STRING_MYSQL = "jdbc:mysql://localhost:3306/velsDB";
String DB_URL_MYSQL_USERID = "root";
String DB_URL_MYSQL_PASSWORD = "root";