Sie sind auf Seite 1von 20

CS31A

Downloading and Installing MySQL

Downloading and Installing MySQL


For this class you should be working with a local installation of MySQL I am assuming a default
installation of MySQL 5.6.

1. Creating an OTN Account


Before you can download Oracle you must create and login to an Oracle Technology Network account.
Go to http://www.oracle.com/index.html to log onto the Oracle Technology Network.

Click on Sign In/Register for Account in the top bar. You should see something like this:

If you already have an Oracle account, enter your new username and password, and then click the "Go"
button to continue.
If you don't already have an Oracle account, click on Create your Oracle account now at the bottom of
the right box. You should see something like the following:

Page 1 of 20

CS31A

Downloading and Installing MySQL

Type in your email address and a password for your new OTN account.
Click Create Account.
Complete the form and click "Create Account" You will find yourself logged into the OTN.
Click on the Downloads tab to get to the Oracle database downloads.
If you look in the upper left hand corner you should see your first name and Sign Out, which
indicates that you are logged onto OTN.

Click on the Downloads link to download Oracle Database 11g Release 2, or click on one of
the links next to Database to get to the downloads page.

Page 2 of 20

CS31A

Downloading and Installing MySQL

There are several versions of MySQL 5.6, and these can be reviewed at www.mysql.com/products/

MySQL Community Server: This is the General Public License (GPL) version of the MySQL
database server, which includes support for both regular, non-transactional storage engines and
transaction-safe tables. It is suited for production environments requiring a stable, flexible, and
robust database engine, and can be downloaded free of charge.

MySQL Enterprise Server: This version is only available as part of the MySQL Enterprise
platform, a commercial offering aimed at enterprise customers with business-critical applications.
It includes all the features of the Community Server, along with automated updates and hot fixes,
consulting support, and monitoring services.

2. Installing MySQL Community Edition


1. Go to the following Web site: http://dev.mysql.com/downloads/
2. Click Downloads and follow the instructions to select and download the Microsoft Windows version
of MySQL.

Click here to go to download


page

This should be the next page you see.


Click this option to go to MySQL Community
Server page.

Page 3 of 20

CS31A

Downloading and Installing MySQL

Scroll down this page and select the


proper version for your system and a site
to begin download..

Download MySQL-installercommunity.

There will be a registration type


form at the top of the page.

Page 4 of 20

CS31A

Downloading and Installing MySQL

3. Once youve got MySQL downloaded, go through the installation process. It may vary somewhat
depending on platform.
Ive illustrated the basic install on Windows 7 over the next few pages, just to give you an idea of
what you should be seeing.

2.1 MySQL Installer


MySQL Installer is an application that simplifies the installation and updating process for a wide range of
MySQL products, including MySQL Notifies for Microsoft Windows, MySQL Workbench, and MySQL
for Excel. MySQL Installer instance can install and manage multiple MySQL Server versions.

Page 5 of 20

CS31A

Downloading and Installing MySQL

2.2 MySQL Installer GUI


After installation of the GUI version, the installer will have its own Start Menu item under MySQL.
After the installer itself has been installed and started, the following screen is displayed:

To Install MySQL Products after executing MySQL


Installer for the first time, you must accept the license
agreement before proceeding with the installation
process

4. Determine the option most compatible with your preferences by reading the Setup Type
Description descriptions.

Your choice here. For


this course, a developer
default , full, or custom
set-up will work fine.
Do Not Select Server
Only or Client Only.

Page 6 of 20

CS31A

Downloading and Installing MySQL

5. On a custom install, youll go through each of the choices on the left menu list. First up will be
setting the features. Selecting which connectors you want loaded.
6. After you select a setup type, the MySQL Installer will check your system for the necessary external
requirements and download then install missing components onto your system
7. The next window lists the MySQL products that are scheduled to be installed
8. As components are installed, you'll see their status change from "to be installed" to "install success."
9. Youre now at the point to download and install the server configuration youve selected. Just click
Execute.

10. When you get all green checkmarks, click Next.


11. Youre now at the point to begin configuring the server. This is where you customize how the server
is to behave. Click Next.
12. Next, choose your account information. Defining a root password is required, whereas it's optional to
create additional users.

Page 7 of 20

CS31A

Downloading and Installing MySQL

13. Select Configuration Type: Development Machine. Check TCP/IP enable. Port will default to 3306,
which is fine. Click Next.
14. You should always set a password for the root account.
15. If the MySQL Server is already installed, then the Current Root Password will also be needed.
16. Next, configure the Windows Service Details. This includes the service name, how the MySQL
Server should be loaded at startup, and how the Windows Service for MySQL Server will be run.
17. We dont need to define any additional user accounts at this point. You can do this later if you wish.

Page 8 of 20

CS31A

Downloading and Installing MySQL

Page 9 of 20

CS31A

Downloading and Installing MySQL

18. After the MySQL Installer configuration process is completed, you may save the installation log, and
then load MySQL Workbench if the Start MySQL Workbench after Setup option is checked:

Page 10 of 20

CS31A

Downloading and Installing MySQL

19. Click Next to begin the MySQL Server configuration. It will start automatically as a service when
this completes.
20. Youre done. The MySQL Server is now running and the MySQL Workbench will start when you
click Finish.
21. This is the MySQL workbench. It is basically waiting for you to select a server to connect to at this
point.

3. Running MySQL
For the examples I use the MySQL command line client that is installed with MySQL. You can use this
command in interactive mode where you enter a query and get a result, then enter another query and get a
result. You can also use the MySQL command line in batch mode where the queries are read from a script
and execute one after the other.
You can do all of your work in the command line client. Some people prefer to work in a graphical
interface (MySQL Workbench).

3.1 Using the MySQL command-line interface


If youve successfully installed MySQL, it should now be running as a service on your machine. It will
start automatically when your machine boots.
MySQL database system provides a command-line interface, called MySQL, which allows the user to
enter SQL commands interactively. One can also include one or more SQL statements in a file and have
them executed within MySQL using the source command.
Page 11 of 20

CS31A

Downloading and Installing MySQL

How to start the MySQL monitor from the Windows Start menu
Start All Programs MySQL MySQL Server MySQL Command Line Client
.

You see this output from MySQL.


The MySQL server is now awaiting
a command from this client.

The MySQL command-line interface is provided by the MySQL application. Some additional parameters
are required to connect to a database:
Once connected to the DBMS, you will be provided with a prompt at which you can enter MySQL
statements.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 5.6.21 MySQL Community Server (GPL)
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be
trademarks of their respective owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

To exit the command-line interface, type exit.

Page 12 of 20

CS31A

Downloading and Installing MySQL

MySQL Workbench
3.2 Using MySQL Workbench
You can do all your work in the command line client but you may find a graphical client helpful. You can
build and test your queries in the graphical client and build up the script. Then run the script to spool
using the command line.
MySQL Workbench is a visual database design tool that integrates SQL development, administration,
database design, creation and maintenance into a single, seamless environment for the MySQL database
system.
What is a MySQL schema?
Schema is MySQLs term for database.
Creating a New MySQL Connection

The SQL Development and Server Administration tools require connections to the database.
1. Open MySQL Workbench by clicking StartAll ProgramMySQLMySQL
Workbench.
2. Having launched the MySQL Workbench, you should now see the following initial
dialog of MySQL Workbench.
New Connection

Page 13 of 20

CS31A

Downloading and Installing MySQL

3. The default connection uses localhost, instead of 127.0.0.1, because it assumes that the
hosts file on Windows hasnt been configured.
4. My example has one connection created, but let us creates a new connection.
5. From the MySQL Workbench Home window, click the icon near the MySQL
Connections label. This opens the Setup New Connection wizard.
6. Click in the Connection Name text field and type CS31A.
7. That prompts you for the password to the root user in the following dialog
8. Click the Test Connection button to check the connection parameters.

Page 14 of 20

CS31A

Downloading and Installing MySQL

9. Our new CS31A MySQL connection is now listed on the Home window.
10. From the Home window, click the new MySQL connection to open the SQL editor for
this connection. The SQL editor is the default page, so now select the Server Status from
the left Navigator panel to display the connected MySQL server's current status.

11. After launching the SQL Development connection, youll see the following MySQL
Workbench dialog. Notice that you can click the home symbol to return to the main menu
at any time.

The Execute the


statement under
the keyboard
cursor button
This is the MySQL workbench main screen. From
here you can create, use, and manage databases as
well as user accounts and the server itself.

Page 15 of 20

CS31A

Downloading and Installing MySQL

How do you create, save, and run an SQL script in MySQL?


To open a script in MySQL Workbench, use the File Open SQL Script . . . menu command. When
the Open Script File dialog box appears, select the script file name and then click the Open button. The
script appears in a tabbed SQL Editor window.
To run the script, click the Execute SQL Script button [The actual name of this button is the Execute the
selected portion of the script or everything, if there is no selection].

This is the MySQL Workbench main


screen shown with the script file
student_schema.sql. This script will
create and populate a small database.
Under File, Select Open SQL Script.
Navigate to where you placed the
script file and open it into this editing
window.

The Execute the


statement under
the keyboard
cursor button

The script executed, which created and


populated the database, then executed the query
at the bottom of the script. Shown in the results
window is the execution results of that query.

Page 16 of 20

CS31A

Downloading and Installing MySQL

A different query executed against the same


database instance.

In the Workbench,
you select a database
by clicking on it.

Page 17 of 20

CS31A

Downloading and Installing MySQL

To see the details of a


tables schema, use the
icons to select more or
less detail.

3.3 How do you create a new database in MySQL?


creating a MySQL database (schema) in the MySQL Workbench requires a few more steps, and
introduces some possible confusion in exactly what is required and in what order!
Creating a MySQL database:
1. Click the Create a new schema in the connected server button
2. The new_schema tabbed window is displayed.

3. Type the new schema (database) name studentdb(lowercase names for schemas are enforced)
in the Name textbox and then click the Apply button.
4. An Apply SQL Script to Database dialog box is displayed so that the user can review the SQL
command before it is executed. Click the Apply button, then the Finish button.
5. The studentdb (the renamed new_schema) dialog box is displayed again. Click the X (Close)
button in the tab.

Page 18 of 20

CS31A

Downloading and Installing MySQL

6. The studentdb schema object now appears in the Object Browser. You may need to click
Refresh Schemas(

)button to refresh the display in the Object Browser:

3.4 What is a MySQL default schema? How do you specify the default schema?
Setting the Default Schema:
1. Click the studentdb schema object in the object browser to select it.
2. Right-click the studentdb schema object to display the shortcut menu:
3. In the shortcut menu, click the Set as Default Schema command.
4. The studentdb schema is set as the active schema (default schema), and the studentdb schema
object is displayed in bold text in the Object Browser to indicate that it is the active schema.

4. User accounts and databases


When you install MySQL you will have a root account and password-which you created during
installation. You would use this account for administrative purposes only.
You could use the admin account to create the databases for this class and then create a user with
privileges on those databases.
If you are logged in to MySQL as the root user, you can create a new MySQL user with the
CREATE USER command:
CREATE USER <user> IDENTIFIED BY '<password>';

where <user> is the name of the new user and <password> is its password. To create a user
with an empty password, you can simply type CREATE USER <user>; skipping the
IDENTIFIED BY part. All user data is stored in the user table in the mysql database.
The command to create a database is CREATE DATABASE followed by the database name.
You use a semicolon to tell the dbms to execute the command.
Example : This is the command to create a user named student with a password of studentpass.
Note the use of quotes in the command.
You can create a student user and studentdb database using this syntax as the root user:
mysql> CREATE USER 'student'@'localhost' IDENTIFIED BY 'studentpass';
After creating the user, you should create a studentdb database. Heres the command syntax:
mysql > CREATE DATABASE studentdb;
This GRANT command gives all permissions on the studentdb to the student user:
Page 19 of 20

CS31A

Downloading and Installing MySQL

Mysql> Grant all privileges on studentdb.* to 'student'@'localhost' ;


Now the student user can use the studentdb database. The connection by itself does not connect the user
to a work area. The student user must tell MySQL which database it wants to use, which connects the user
to a work area. You do that with the following command:
Mysql >USE studentdb
You can change databases at any time, but you must disconnect and reconnect when you want to change
the user.

Page 20 of 20

Das könnte Ihnen auch gefallen