mysql introduction - university of kansashossein/teaching/su09/lectures/my-sql-intro.pdfrequirements...

25
MySQL Introduction EECS 746 Summer 2007

Upload: others

Post on 06-Aug-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: MySQL Introduction - University of Kansashossein/Teaching/Su09/Lectures/my-sql-intro.pdfRequirements [1/2] Processor - Pentium ||| 733 MHz or higher Memory - 128 MB RAM or more Disk

MySQL IntroductionEECS 746

Summer 2007

Page 2: MySQL Introduction - University of Kansashossein/Teaching/Su09/Lectures/my-sql-intro.pdfRequirements [1/2] Processor - Pentium ||| 733 MHz or higher Memory - 128 MB RAM or more Disk

OverviewRequirementsInstallationUsage

Page 3: MySQL Introduction - University of Kansashossein/Teaching/Su09/Lectures/my-sql-intro.pdfRequirements [1/2] Processor - Pentium ||| 733 MHz or higher Memory - 128 MB RAM or more Disk

Benefits of MySQLFreeFastStablePopularCross platform

Page 4: MySQL Introduction - University of Kansashossein/Teaching/Su09/Lectures/my-sql-intro.pdfRequirements [1/2] Processor - Pentium ||| 733 MHz or higher Memory - 128 MB RAM or more Disk

Requirements [1/2]Processor - Pentium ||| 733 MHz or higherMemory - 128 MB RAM or moreDisk space - 270 MB or more

Page 5: MySQL Introduction - University of Kansashossein/Teaching/Su09/Lectures/my-sql-intro.pdfRequirements [1/2] Processor - Pentium ||| 733 MHz or higher Memory - 128 MB RAM or more Disk

Requirements [2/2]Administrator rightsTCP/IP protocol supportDrivers (ODBC, .NET, Visual Studio, PHP ...)

http://dev.mysql.com/doc/refman/5.0/en/connectors.html

Page 6: MySQL Introduction - University of Kansashossein/Teaching/Su09/Lectures/my-sql-intro.pdfRequirements [1/2] Processor - Pentium ||| 733 MHz or higher Memory - 128 MB RAM or more Disk

Versions6.0 - Alpha5.1 - Beta5.0 - Stable (Recommended)4.1 - Stable

Page 7: MySQL Introduction - University of Kansashossein/Teaching/Su09/Lectures/my-sql-intro.pdfRequirements [1/2] Processor - Pentium ||| 733 MHz or higher Memory - 128 MB RAM or more Disk

Supported OSWindowsWindows x64Linux (Red Hat, SuSE, Ubuntu, etc.)Mac OS X

http://dev.mysql.com/downloads/mysql/

Page 8: MySQL Introduction - University of Kansashossein/Teaching/Su09/Lectures/my-sql-intro.pdfRequirements [1/2] Processor - Pentium ||| 733 MHz or higher Memory - 128 MB RAM or more Disk

GUI ToolsMySQL Administrator 1.2MySQL Query Browser 1.2

http://dev.mysql.com/downloads/gui-tools/

Navicat administration and development toolhttp://www.navicat.com/download.html

Page 9: MySQL Introduction - University of Kansashossein/Teaching/Su09/Lectures/my-sql-intro.pdfRequirements [1/2] Processor - Pentium ||| 733 MHz or higher Memory - 128 MB RAM or more Disk

Installation [1/9]

Page 10: MySQL Introduction - University of Kansashossein/Teaching/Su09/Lectures/my-sql-intro.pdfRequirements [1/2] Processor - Pentium ||| 733 MHz or higher Memory - 128 MB RAM or more Disk

Installation [2/9]

Page 11: MySQL Introduction - University of Kansashossein/Teaching/Su09/Lectures/my-sql-intro.pdfRequirements [1/2] Processor - Pentium ||| 733 MHz or higher Memory - 128 MB RAM or more Disk

Installation [3/9]

Page 12: MySQL Introduction - University of Kansashossein/Teaching/Su09/Lectures/my-sql-intro.pdfRequirements [1/2] Processor - Pentium ||| 733 MHz or higher Memory - 128 MB RAM or more Disk

Installation [4/9]

Page 13: MySQL Introduction - University of Kansashossein/Teaching/Su09/Lectures/my-sql-intro.pdfRequirements [1/2] Processor - Pentium ||| 733 MHz or higher Memory - 128 MB RAM or more Disk

Installation [5/9]

Page 14: MySQL Introduction - University of Kansashossein/Teaching/Su09/Lectures/my-sql-intro.pdfRequirements [1/2] Processor - Pentium ||| 733 MHz or higher Memory - 128 MB RAM or more Disk

Installation [6/9]

Page 15: MySQL Introduction - University of Kansashossein/Teaching/Su09/Lectures/my-sql-intro.pdfRequirements [1/2] Processor - Pentium ||| 733 MHz or higher Memory - 128 MB RAM or more Disk

Installation [7/9]

Page 16: MySQL Introduction - University of Kansashossein/Teaching/Su09/Lectures/my-sql-intro.pdfRequirements [1/2] Processor - Pentium ||| 733 MHz or higher Memory - 128 MB RAM or more Disk

Installation* [8/9]

Page 17: MySQL Introduction - University of Kansashossein/Teaching/Su09/Lectures/my-sql-intro.pdfRequirements [1/2] Processor - Pentium ||| 733 MHz or higher Memory - 128 MB RAM or more Disk

Installation [9/9]

Page 18: MySQL Introduction - University of Kansashossein/Teaching/Su09/Lectures/my-sql-intro.pdfRequirements [1/2] Processor - Pentium ||| 733 MHz or higher Memory - 128 MB RAM or more Disk

Usage [1/3]

Page 19: MySQL Introduction - University of Kansashossein/Teaching/Su09/Lectures/my-sql-intro.pdfRequirements [1/2] Processor - Pentium ||| 733 MHz or higher Memory - 128 MB RAM or more Disk

Usage [2/3]

Page 20: MySQL Introduction - University of Kansashossein/Teaching/Su09/Lectures/my-sql-intro.pdfRequirements [1/2] Processor - Pentium ||| 733 MHz or higher Memory - 128 MB RAM or more Disk

Usage [3/3]

Page 21: MySQL Introduction - University of Kansashossein/Teaching/Su09/Lectures/my-sql-intro.pdfRequirements [1/2] Processor - Pentium ||| 733 MHz or higher Memory - 128 MB RAM or more Disk

OperatorsControl Flow FunctionsString FunctionsNumeric FunctionsDate and Time FunctionsAggregate Functions

http://dev.mysql.com/doc/refman/5.0/en/functions.html

http://www.ilovejackdaniels.com/mysql_cheat_sheet.png

MySQL Functions

Page 22: MySQL Introduction - University of Kansashossein/Teaching/Su09/Lectures/my-sql-intro.pdfRequirements [1/2] Processor - Pentium ||| 733 MHz or higher Memory - 128 MB RAM or more Disk

PHP Example<?php$link=mysql_connect('localhost', 'mysql_user', 'mysql_password');

mysql_select_db('my_database');

$query='SELECT * FROM my_table';$result=mysql_query($query);

echo "<table>\n";while ($line=mysql_fetch_array($result, MYSQL_ASSOC)){ echo "\t<tr>\n"; foreach ($line as $col_value)

echo "\t\t<td>$col_value</td>\n"; echo "\t</tr>\n";}echo "</table>\n";

mysql_free_result($result);

mysql_close($link);

Page 23: MySQL Introduction - University of Kansashossein/Teaching/Su09/Lectures/my-sql-intro.pdfRequirements [1/2] Processor - Pentium ||| 733 MHz or higher Memory - 128 MB RAM or more Disk

ASP.NET Example<%@ Page Language="C#" %><%@ Import Namespace="System.Data" %><%@ Import Namespace="System.Data.Odbc" %><script runat="server">

private const string ConnStr="Driver={MySQL ODBC 3.51 Driver};" +"Server=localhost;Database=my_database;uid=mysql_user;pwd=mysql_password;option=3";protected override void OnInit(EventArgs e){

base.OnInit(e);using(OdbcConnection con=new OdbcConnection(ConnStr))using(OdbcCommand cmd=new OdbcCommand("SELECT * FROM my_table", con)){

con.Open();my_data_source.DataSource=cmd.ExecuteReader(CommandBehavior.CloseConnection | CommandBehavior.SingleResult);my_data_source.DataBind();

}}

</script>

<asp:DataGrid ID="my_data_source" HorizontalAlign="Center" CellPadding="3" Runat="server" />

Page 24: MySQL Introduction - University of Kansashossein/Teaching/Su09/Lectures/my-sql-intro.pdfRequirements [1/2] Processor - Pentium ||| 733 MHz or higher Memory - 128 MB RAM or more Disk

Java Exampleimport java.sql.*;

public class j_example{

public static void main(String args[]){

String url="jdbc:mysql://localhost:3306/my_database";Connection con=DriverManager.getConnection(url, "mysql_user", "mysql_password");

Statement stmt=con.createStatement(); ResultSet rs=stmt.executeQuery("SELECT * FROM my_table");

while(rs.next()) {

String str=rs.getString("my_column"); System.out.println(str);}

con.close();}

}

Page 25: MySQL Introduction - University of Kansashossein/Teaching/Su09/Lectures/my-sql-intro.pdfRequirements [1/2] Processor - Pentium ||| 733 MHz or higher Memory - 128 MB RAM or more Disk