MySQL Introduction - University of Kansas · Requirements [1/2] Processor - Pentium ||| 733 MHz or...

25
MySQL Introduction EECS 746 Summer 2007

Transcript of MySQL Introduction - University of Kansas · Requirements [1/2] Processor - Pentium ||| 733 MHz or...

Page 1: MySQL Introduction - University of Kansas · Requirements [1/2] Processor - Pentium ||| 733 MHz or higher Memory - 128 MB RAM or more Disk space - 270 MB or more

MySQL IntroductionEECS 746

Summer 2007

Page 2: MySQL Introduction - University of Kansas · Requirements [1/2] Processor - Pentium ||| 733 MHz or higher Memory - 128 MB RAM or more Disk space - 270 MB or more

OverviewRequirementsInstallationUsage

Page 3: MySQL Introduction - University of Kansas · Requirements [1/2] Processor - Pentium ||| 733 MHz or higher Memory - 128 MB RAM or more Disk space - 270 MB or more

Benefits of MySQLFreeFastStablePopularCross platform

Page 4: MySQL Introduction - University of Kansas · Requirements [1/2] Processor - Pentium ||| 733 MHz or higher Memory - 128 MB RAM or more Disk space - 270 MB or more

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 Kansas · Requirements [1/2] Processor - Pentium ||| 733 MHz or higher Memory - 128 MB RAM or more Disk space - 270 MB or more

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 Kansas · Requirements [1/2] Processor - Pentium ||| 733 MHz or higher Memory - 128 MB RAM or more Disk space - 270 MB or more

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

Page 7: MySQL Introduction - University of Kansas · Requirements [1/2] Processor - Pentium ||| 733 MHz or higher Memory - 128 MB RAM or more Disk space - 270 MB or more

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

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

Page 8: MySQL Introduction - University of Kansas · Requirements [1/2] Processor - Pentium ||| 733 MHz or higher Memory - 128 MB RAM or more Disk space - 270 MB or more

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 Kansas · Requirements [1/2] Processor - Pentium ||| 733 MHz or higher Memory - 128 MB RAM or more Disk space - 270 MB or more

Installation [1/9]

Page 10: MySQL Introduction - University of Kansas · Requirements [1/2] Processor - Pentium ||| 733 MHz or higher Memory - 128 MB RAM or more Disk space - 270 MB or more

Installation [2/9]

Page 11: MySQL Introduction - University of Kansas · Requirements [1/2] Processor - Pentium ||| 733 MHz or higher Memory - 128 MB RAM or more Disk space - 270 MB or more

Installation [3/9]

Page 12: MySQL Introduction - University of Kansas · Requirements [1/2] Processor - Pentium ||| 733 MHz or higher Memory - 128 MB RAM or more Disk space - 270 MB or more

Installation [4/9]

Page 13: MySQL Introduction - University of Kansas · Requirements [1/2] Processor - Pentium ||| 733 MHz or higher Memory - 128 MB RAM or more Disk space - 270 MB or more

Installation [5/9]

Page 14: MySQL Introduction - University of Kansas · Requirements [1/2] Processor - Pentium ||| 733 MHz or higher Memory - 128 MB RAM or more Disk space - 270 MB or more

Installation [6/9]

Page 15: MySQL Introduction - University of Kansas · Requirements [1/2] Processor - Pentium ||| 733 MHz or higher Memory - 128 MB RAM or more Disk space - 270 MB or more

Installation [7/9]

Page 16: MySQL Introduction - University of Kansas · Requirements [1/2] Processor - Pentium ||| 733 MHz or higher Memory - 128 MB RAM or more Disk space - 270 MB or more

Installation* [8/9]

Page 17: MySQL Introduction - University of Kansas · Requirements [1/2] Processor - Pentium ||| 733 MHz or higher Memory - 128 MB RAM or more Disk space - 270 MB or more

Installation [9/9]

Page 18: MySQL Introduction - University of Kansas · Requirements [1/2] Processor - Pentium ||| 733 MHz or higher Memory - 128 MB RAM or more Disk space - 270 MB or more

Usage [1/3]

Page 19: MySQL Introduction - University of Kansas · Requirements [1/2] Processor - Pentium ||| 733 MHz or higher Memory - 128 MB RAM or more Disk space - 270 MB or more

Usage [2/3]

Page 20: MySQL Introduction - University of Kansas · Requirements [1/2] Processor - Pentium ||| 733 MHz or higher Memory - 128 MB RAM or more Disk space - 270 MB or more

Usage [3/3]

Page 21: MySQL Introduction - University of Kansas · Requirements [1/2] Processor - Pentium ||| 733 MHz or higher Memory - 128 MB RAM or more Disk space - 270 MB or more

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 Kansas · Requirements [1/2] Processor - Pentium ||| 733 MHz or higher Memory - 128 MB RAM or more Disk space - 270 MB or more

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 Kansas · Requirements [1/2] Processor - Pentium ||| 733 MHz or higher Memory - 128 MB RAM or more Disk space - 270 MB or more

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 Kansas · Requirements [1/2] Processor - Pentium ||| 733 MHz or higher Memory - 128 MB RAM or more Disk space - 270 MB or more

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 Kansas · Requirements [1/2] Processor - Pentium ||| 733 MHz or higher Memory - 128 MB RAM or more Disk space - 270 MB or more