Published on

Published in: Technology
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide


  3. 3. Installing MySQL on Windows Introduction <ul><li>Introduction </li></ul><ul><li>Installing MySQL </li></ul><ul><li>Running MySQL </li></ul><ul><li>Testing with PHP </li></ul><ul><li>Presented by Mike Barras, ITS </li></ul><ul><li>Available online at </li></ul>
  4. 4. Installing MySQL on Windows Introduction <ul><li>Supported 32-bit Windows Platforms (Win32) </li></ul><ul><ul><li>Windows 9x (95/98/ME) </li></ul></ul><ul><ul><li>Windows NT (NT/2000/XP) </li></ul></ul><ul><li>Workstation/Home/Professional </li></ul><ul><li>Server Editions </li></ul>
  5. 5. Installing MySQL on Windows Installing MySQL <ul><li>Example environment </li></ul><ul><ul><li>Windows 2000 Server (SP 3) </li></ul></ul><ul><ul><li>IIS 5.0 </li></ul></ul><ul><ul><li>PHP 4.3.1 </li></ul></ul><ul><ul><li>MySQL 4.0.12 </li></ul></ul><ul><li>Note: IIS (Web Server) and PHP (Script engine) are </li></ul><ul><li>NOT required to install or run MySQL. </li></ul>
  6. 6. Installing MySQL on Windows Installing MySQL Step 1: Download the most recent version of the MySQL for Windows installer from http://www.mysql.org/ , and run it. Select the directory to which you would like to install MySQL (c:mysql).
  7. 7. Installing MySQL on Windows Installing MySQL <ul><li>Step 2: Select the setup type that you would like to use. The </li></ul><ul><li>“ typical” should be sufficient for just about everybody. It </li></ul><ul><li>installs all items, including: </li></ul><ul><li>The Mysql Servers </li></ul><ul><li>Clients and maint. tools </li></ul><ul><li>Documentation </li></ul><ul><li>Examples and Libraries </li></ul><ul><li>Grants tables and core </li></ul><ul><li>files </li></ul>
  8. 8. Installing MySQL on Windows Installing MySQL Step 3: That’s it! Click finish and you’re done installing (it really is just that simple)
  9. 9. Installing MySQL on Windows Running MySQL You must manually start MySQL the first time. c:mysqlinwinmysqladmin.exe You will be prompted to create an admin username and Password. This is the login information for the admin tool, not any specific database or table. Once the admin account is created, the server will be running (either as a program in Win 9x or as a service in NT) and will run each time you start Windows. The “traffic light” system tray icon shows you its working.
  10. 10. Installing MySQL on Windows Running MySQL Run the MySQL command interface by executing c:mysqlinmysql.exe Type show databases; to See the current databases Configured on the server. By default, “mysql” and “ test” should be there. Type use test; to specify that database.
  11. 11. Installing MySQL on Windows Running MySQL Let’s create a table. Type show tables; to see Currently defined tables in “ test”. Issue create table command to create a table. Now run show tables; again to verify what you’ve done. create table tablename ( column datatype );
  12. 12. Installing MySQL on Windows Running MySQL Insert some data into the table you’ve just created using the “insert into” SQL command. Verify the insert by “selecting” the information back out. insert into tablename ( field1, field2,… ) values ( value1, value2,… ); select [list of fieldnames or *] from tablename;
  13. 13. Installing MySQL on Windows Testing with PHP The true measure of success (requires PHP and web server) Put it all together. PHP Functions: mysql_connect( host[,user,pass] ) mysql_select_db( database ) mysql_query( SQL stmt ); mysql_close( database handle );
  14. 14. Installing MySQL on Windows Testing with PHP
  15. 15. Installing PHP on Windows Useful Links This Presentation http:// uts.cc.utexas.edu/~mpbarras/php / Download MySQL http://www.mysql.com/downloads/mysql-4.0.html Installation Documentation http://www.mysql.com/documentation/index.html PHP reference for MySQL functions http://www.php.net/manual/en/ref.mysql.php
  16. 16. BASIC SQL COMMANDS SQL STATEMENTS: T here are a number of SQL statements, few of which are explained below: Data Retrieval Statement: SELECT is the data extracting statement which retrieves the data from the database. Data Manipulation Language (DML): This language constitutes the statements that are used to manipulate with the data. It has three commands, which are INSERT, UPDATE and DELETE. Data Definition Language (DDL): This is the language used to define the tables. It sets up, changes, and removes data structures from the tables. It uses 5 commands, which are CREATE, ALTER, DROP, RENAME and TRUNCATE.
  17. 17. <ul><li>CREATING A TABLE </li></ul>Syntax: Create table <Table Name> ( <Field1> <Type> <(width)> [Not Null/Null], <Field2> <Type> <(width)> [Not Null/Null], ..................................) : Example: Create table student_table (Reg_No Text (6) Name Text (25), Class Text (5));
  18. 18. <ul><li>CREATING A TABLE WITH PRIMARY KEY </li></ul>Syntax: Create table <Table Name> ( <Field1> <Type> <(width)> Constraint <constraint name> Primary Key , <Field2> <Type> <(width)>, ..................................) : Example: a) Create table student_table2 (Reg_no Text (4) Constraint student_Reg_pk primary key, Name Text (25), Class Text (5));
  19. 19. CREATING A TABLE WITH COMPOSITE PK <ul><li>Syntax: </li></ul><ul><li>Create table <Table Name> </li></ul><ul><li>( <Field1> <Type> <(width)> , </li></ul><ul><li><Field2> <Type> <(width)>, </li></ul><ul><li>..................................<field-n> <type-n> <width-n>, </li></ul><ul><li>Constraint <constraint-name> Primary Key (Field1, Field2)) : </li></ul>Example: Create table student_table3 (Reg_no Text (4), Name Text (25), Class Text (5), Constraint student_Reg_Class_pk primary key (Reg_no, Class));  
  20. 20. CREATING A TABLE WITH FOREIGN KEY <ul><li>Create table student_table2 </li></ul><ul><li>(Reg_no Text (4), </li></ul><ul><li>Name Text (25), </li></ul><ul><li>Class Text (5) </li></ul><ul><li>Proj_No Text (4) </li></ul><ul><li>Constraint student_Reg_pk primary key (Reg_no) </li></ul><ul><li>Constraint project_PNo_fk Foreign Key (Proj_No) </li></ul><ul><li>References Project (Proj_No)); </li></ul>
  21. 21. To Delete a Table along with all contents <ul><li>Syntax: </li></ul><ul><li>Drop Table <Table-Name>; </li></ul>Example: Drop Table student_table2;
  22. 22. To Add a field to the table (structure) <ul><li>Syntax: </li></ul><ul><li>Alter Table <Table-Name> </li></ul><ul><li>Add <Field Name> <Type> (width); </li></ul>Example: Alter Table Student_Table Add Roll_no Text (4);
  23. 23. To Insert Data Into a Table <ul><li>a) Syntax: </li></ul><ul><li>Insert Into <Table-Name> (Fieldname1, Fieldname2, Fieldname3,..) </li></ul><ul><li>Values (value1, value2, value3,..) </li></ul><ul><li>Example: </li></ul><ul><li>Insert Into Student_Table (Reg_no, Name, class) </li></ul><ul><li>Values (1211, &quot;Umar&quot;, &quot;MCS&quot;); </li></ul>;
  24. 24. Example: b-1) Insert Into Student_Table Values (1123, &quot;Babar&quot;, null, null); b-2) Insert Into Student_Table (Reg_no, Name, class, Roll_no) Values (1124, &quot;Babar&quot;, null, null); b-3) Insert Into Student_Table (Reg_no, Name) Values (1124, &quot;Babar&quot;); b) Syntax: Insert Into <Table-Name> Values (value1, value2, value3,.., value-n);
  25. 25. To Delete a Row or Rows (Records) <ul><li>Syntax: </li></ul><ul><li>Delete from <table name> </li></ul><ul><li>[where <condition>]; </li></ul>Example: a) Delete from student_table; (it will delete al the records from student table).   b) Delete from student_table (conditional deletion) Where class=&quot;MCS&quot;;
  26. 26. Modifying (Updating) Records: <ul><li>Syntax: </li></ul><ul><li>UPDATE <table name> </li></ul><ul><li>Set <Field Name> = <Value> </li></ul><ul><li>Where <Condition>; </li></ul>Example: a) UPDATE Student Set Semester = 5 where Semester = 4 or Class = “MCS”; b) UPDATE Student Set Semester = 5, Class = “MS” where Semester = 4 or Class = “MCS”;
  27. 27. Creating a View: <ul><li>Syntax: </li></ul><ul><li>CREATE VIEW <View-Name> AS </li></ul><ul><li>Select Field1, Field2, Field3 </li></ul><ul><li>From <Table_Name> </li></ul>Example: CREATE VIEW Student_BCS as Select Reg_No, Name, Class From Student Where Class = “BCS”;  
  28. 28. Querying a View: <ul><li>Syntax: </li></ul><ul><li>Select <Field List> </li></ul><ul><li>From <View Name> </li></ul><ul><li>Where <condition>; </li></ul>Example: a) Select * From Student_BCS ; b) Select * From Student_BCS where City = “Islamabad”;
  29. 29. Retrieving (Displaying) Data: <ul><li>Syntax: </li></ul><ul><li>Select <field1, field2, ……fieldn> </li></ul><ul><li>from <table name> </li></ul><ul><li>where <condition>; </li></ul>Example: a) SELECT * FROM Student_table;   b) SELECT Reg_no, Name FROM Student_table;
  30. 30. Retrieving (Displaying) Data depending on some condition: <ul><li>Syntax: </li></ul><ul><li>Select <field1, field2, ……fieldn> </li></ul><ul><li>from <table name> </li></ul><ul><li>Where <Condition>; </li></ul>Example: a) Select * From Student_table Where class= &quot;BCS&quot;;   b) Select Name, Reg_no From Student_table Where class= &quot;BCS&quot;;
  31. 31. THANK YOU