Transcript MySQL

MySQL
井民全製作 http://debut.cis.nctu.edu.tw/~ching
General Information
• The MySQL™
– delivers a fast, multi-threaded, multi-user, and robust SQL
database server
• SQL Structured Query Language
– is intended for mission-critical, heavy-load production
– MySQL™ is a trademark of MySQL AB
• Dual license
GNU: http://www.gnu.org/licenses/
– Open Source / Freeware software product under GNU
– Purchase a standard commercial license from SQL AB
• The last information
– MYSQL web site  http://www.mysql.com
You need a commercial
license
• Link with any GPL code from the MySQL
–software
• Distribute a application only work with the
MySQL and ship it with the MySQL
software
• Distribute copies of MySQL without
providing the source code
• Support the further development of the
SQL database
For more information
see MySQL Reference Manual1.4.3.1 Using the MySQL Software Under a Commercial License
What is MYSQL
• is a database management system (DBMS)
– a structured collection data
– add and process data in a computer
• is a relational DBMS
– store data in separate tables
– the tables are linked by relations
• is open source
– it is possible for anyone to modify
– using the software without paying anything
Installing MySQL
• How to get MySQL
– Check the homepage (http://www.mysql.com)
• Operating System Supported
– AIX, Amiga, BSD, DEC, FreeBSD, HP-UX, Linux2.0,
MacOS, NetBSD, OpenBSD, OS2/Warp, SGI Irix6.x,
Solaris 2.5, SunOS 4.x, Caldera(SCO) OpenServer, Tru65
Unix, Windows 9x Me NT 2000 andXP
Installation Layout
Installing MySQL on Windows
• Can running MySQL as a service
• Install MySQL on the NTFS if you want your table
bigger than 4G
• TCP/IP protocol support
• Connected to the MySQL
– via ODBC you need MyODBC driver
• MyODBC: http://www.mysql.com/downloads/api-myodbc.html
– Via JDBC you need mm driver or Reisin driver
• mmdriver:
http://www.mysql.com/Downloads/Contrib/
• Reisin: http://www.caucho.com/projects/jdbc-mysql/index.xtp
Download address
http://www.mysql.com/downloads/
Installing the Binaries
• Stop the earlier installation
– C:\mysql\bin> mysqladmin -u root shutdown
– Remove the service : C:\mysql\bin> mysqld-max-nt --remove
Setup
• Starting the Server for the first time
•
C:\mysql\bin\mysqld-nt --install
Remove the service
using --remove
Stop the service
using net stop MySQL
Start the service
using net start
MySQL
Manager your server
• WinMYSQLadmin.exe
Functions
1. Start the service
2. Stop the service
3. Edit the My.ini
…
Connect to your server
• Client
– Mysql.exe
• Quit
• List all databases
– Show databases;
• Using database
– USE test
// 注意沒有 ;
» Drop table mytable2;
• List all tables
– Show tables;
• Create database
– Create database 新資料庫名稱;
JDBC Driver for MySQL
• MySQL Connector/J
– Licensed under GPL and commercial license
[see MySQLEULA.txt]
– How to get Connector/J
• http://www.mysql.com
• Installation
– S1: mysql-connector-java-3.0.7-stable-bin.jar  c:\mysql
– S2: setup the JBuilder
• Configure Libraries… : New a library & set the library path
• Project Properties: Add the required libraries
Connector/J
-- JBuilder Setup
• Configure Libraries
2
Give a name for the library
3
Add the library path
1
Connector/J
-- Project Properties
1
2
Add the Mysql library the your
project
Test Connector/J now
Create table
import java.sql.*;
public class CreateTable {
public static void main(String[] args)throws Exception {
Class.forName("com.mysql.jdbc.Driver").newInstance();
Load the Driver
Connect to the DataBase
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost/test");
Execute the SQL command
}
}
Statement sqlStmt=conn.createStatement();
String strcreateTable="create table MYTABLE(" +
"Text char(10)" +
")";
sqlStmt.executeUpdate(strcreateTable);
System.out.println("Ok");
Example: MySQLTest1CreateTable
Test Connector/J now
import java.sql.*;
public class CreateTable {
public static void main(String[] args)throws Exception {
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost/test?
useUnicode=true&characterEncoding=MS950"); Connect to the DataBase
Statement sqlStmt=conn.createStatement();
String strInsert="insert into mytable3 values(\"'宏碁資訊'\");";
sqlStmt.executeUpdate(strInsert);
}
}
System.out.println("Ok");