MySQL in Windows Vista: Creating a database, table and inserting data using script

The MySQL have the interactive command line to enter your transaction to the database server but what if you wanted to it using script?

In Windows Operating system files with *.bat file extension can be executed. So, what I did is create the files and corresponding content:

Users.bat


 

mysql -h localhost -u root -p < procedure1.txt


 

Explaination: This command will connect to the MySQL server in the localhost with username as root and the password will be asked. The procedure1.txt contains additional commands to be executed in MySQL.

Procedure1.txt

CREATE DATABASE usersdatabase;

USE usersdatabase;

CREATE TABLE users (username CHAR(50) DEFAULT '' NOT NULL,

password CHAR(50) DEFAULT '' NOT NULL,

accesslevel INT(4) UNSIGNED ZEROFILL DEFAULT '0000' NOT NULL,

PRIMARY KEY(username));

INSERT INTO users VALUES

('professor','prof$532*&^%!@',20), ('student','stu%%$#@!8973',10),

('sysadmin','sysad!!*&^55432%^',100),('librarian','lib&^^%$#@123',30),

('facilityad','facad@@#$#%1467',40),('adminstaff','adminstaff***&^%983781',50),

('admin','admin100298987493874',60);


 

Explaination: This will create the database and select the database usersdatabase then after that create the table users with its columns and data inside


 

When you execute users.bat the script will do everything so you won't have to do anything. Putting all you commands in a script will save you time specially during software installation in setting up the initial database.

Comments

Popular posts from this blog

Creating tray application and popup context menu in Windows

How to statically link applications to wxWidgets via Visual Studio 2008 and in Linux

How to put an image to wxPanel using wxWidgets