MySQL
Installing MySQL
- Download from mysql.org
- Double-click on zip to begin install process
- I selected Detailed, included Embedded and Examples, Development
system, Multi use, Store files on C:\MySQL DataFiles, Use DSS, 5-user
connect, TCP/IP, port 3306, Std char set, don't launch automatically,
include bin in path, I added a password, root only from localhost
(important because of new security risks), no anonymous logins.
Using MySQL
- MySQL includes both a Server and a Client
- After installation, the Server can be started (on XP Systems) via
Control Panel ->Administrative Tools -> Services. Select
Start.
- The Client is availabe via either the Command Prompt or Start
-> All Programs -> MySQL -> MySQL 4.1 -> Command Line
Client.
- DOS Prompt: connect to MySQL via a host (localhost) and username
(root)
- Commands can by typed directly into the mysql shell or issued as
a batch
- A command is normally an SQL statement followed by a semicolon
- Keywords are not case sensitive
- Commands can span multiple lines. Clear a partial entry by
typing \c
- Strings can be surrounded by ' or " and can span multiple lines
- USE databaseName
- Database names are case sensitive
Connecting to MySQL from with Java
- Download connector
- Unzip, read info in docs/index.html
- See programs on Blackboard
- To compile in Eclipse, Select Project->Properties->Build
Path-> Libraries -> Add Exernal Jar and find the
mysql-connector-java-3.1.6-bin.jar file.
- To compile manually, you must add the above jar file to your
classpath.
Example:
//DriverManager establishes connection to database
// Needs to find jdbc driver
Class.forName( "com.mysql.jdbc.Driver" );
// connect to database books, user root with
password macs443
Connection connection = DriverManager.getConnection(
"jdbc:mysql://localhost/books?user=root&password=macs443" );