Top Banner
Installing and Using MySQL and phpMyAdmin
28

Installing and Using MySQL and phpMyAdmin. Last Time... Installing Apache server Installing PHP Running basic PHP scripts on the server Not necessary.

Jan 01, 2016

Download

Documents

Daniella Snow
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Installing and Using MySQL and phpMyAdmin. Last Time... Installing Apache server Installing PHP Running basic PHP scripts on the server Not necessary.

Installing and Using MySQL and phpMyAdmin

Page 2: Installing and Using MySQL and phpMyAdmin. Last Time... Installing Apache server Installing PHP Running basic PHP scripts on the server Not necessary.

Last Time...

• Installing Apache server• Installing PHP• Running basic PHP scripts on the server

• Not necessary to have Apache and PHP working to understand this webcast, but we will be putting everything together next week!

Page 3: Installing and Using MySQL and phpMyAdmin. Last Time... Installing Apache server Installing PHP Running basic PHP scripts on the server Not necessary.

Today...

• Installing MySQL server on your computer (easy!)

• Installing phpMyAdmin (not quite as easy, but still not too bad)

• All about MySQL queries

Page 4: Installing and Using MySQL and phpMyAdmin. Last Time... Installing Apache server Installing PHP Running basic PHP scripts on the server Not necessary.

Download and Install MySQL

Get an msi installer from this page:

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

“Standard installation” with default settings should work just fine.

Be sure to remember your password!

Page 5: Installing and Using MySQL and phpMyAdmin. Last Time... Installing Apache server Installing PHP Running basic PHP scripts on the server Not necessary.

Command Line ClientOpen the Command Line Client.

Try typing the command “show databases.” This is what you’ll see:

Page 6: Installing and Using MySQL and phpMyAdmin. Last Time... Installing Apache server Installing PHP Running basic PHP scripts on the server Not necessary.

Creating a DatabaseMake up a name for your first database and try the command “create database databasename.”

Page 7: Installing and Using MySQL and phpMyAdmin. Last Time... Installing Apache server Installing PHP Running basic PHP scripts on the server Not necessary.

Creating a TableType “use databasename;” to switch to your database.

Use the command “create table tablename (fields)” to make a table in your database.

To make an integer field, say “fieldname integer” in the parentheses. To make a text field, say “fieldname char(20)” (this makes a field where the maximum number of characters is 20- you can make a different limit if you’d like).

Page 8: Installing and Using MySQL and phpMyAdmin. Last Time... Installing Apache server Installing PHP Running basic PHP scripts on the server Not necessary.

Adding DataUse the command “insert into tablename (fieldnames) values (values)” to add data to the table.

Use ‘single quotes’ around text.

You can add multiple entries at a time (see the example below).

Page 9: Installing and Using MySQL and phpMyAdmin. Last Time... Installing Apache server Installing PHP Running basic PHP scripts on the server Not necessary.

Retrieving DataType “select fieldname from tablename” to see the information in the table.

Use a comma-separated list to view multiple columns in the table. Use a * to see all columns.

Page 10: Installing and Using MySQL and phpMyAdmin. Last Time... Installing Apache server Installing PHP Running basic PHP scripts on the server Not necessary.

Using “where” (as well as “and”, “or”, “not”)

Page 11: Installing and Using MySQL and phpMyAdmin. Last Time... Installing Apache server Installing PHP Running basic PHP scripts on the server Not necessary.

Delete“Delete” works just like “select.”

Use with caution.

Page 12: Installing and Using MySQL and phpMyAdmin. Last Time... Installing Apache server Installing PHP Running basic PHP scripts on the server Not necessary.

Multiple Tables

You can create many tables within the same database.

A common practice is to use ID numbers to reference information from other tables.

Page 13: Installing and Using MySQL and phpMyAdmin. Last Time... Installing Apache server Installing PHP Running basic PHP scripts on the server Not necessary.

Multiple Tables

You can create many tables within the same database.

A common practice is to use ID numbers to reference information from other tables.

Page 14: Installing and Using MySQL and phpMyAdmin. Last Time... Installing Apache server Installing PHP Running basic PHP scripts on the server Not necessary.

Join QueriesQueries can use more than one table. The first query shows which names are paired with which books.

“select addresses.name, books.book from addresses, books where addresses.ID = books.person;”

Challenge: write a query that picks out the e-mail addresses of people who like Lord of the Rings.

Page 15: Installing and Using MySQL and phpMyAdmin. Last Time... Installing Apache server Installing PHP Running basic PHP scripts on the server Not necessary.

More Examples

Try to write queries to display the following information:

- One column: just all the e-mail addresses

- Two columns: names and corresponding favorite bands

- One column: people who liked The Beatles also liked which books?

Page 16: Installing and Using MySQL and phpMyAdmin. Last Time... Installing Apache server Installing PHP Running basic PHP scripts on the server Not necessary.

Installing phpMyAdmin

• phpMyAdmin provides a useful GUI so we don’t have to use the command line all the time

• Download phpMyAdmin at http://www.phpmyadmin.net/home_page/downloads.php

• Extract the files into a folder named “phpMyAdmin” in your Apache server folder

Page 17: Installing and Using MySQL and phpMyAdmin. Last Time... Installing Apache server Installing PHP Running basic PHP scripts on the server Not necessary.

Before editing config file...

• Go to localhost/phpmadmin/index.php

• You should see the phpMyAdmin login page, but with error messages. You might not be able to login yet.

Page 18: Installing and Using MySQL and phpMyAdmin. Last Time... Installing Apache server Installing PHP Running basic PHP scripts on the server Not necessary.

Editing the Config File

• Find config.sample.inc.php in your phpMyAdmin folder.

• Find the line that says $cfg['blowfish_secret'] = ''; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */

• Put any word you want into the quotes, (i.e. $cfg['blowfish_secret'] = ‘caddywhompus’

Page 19: Installing and Using MySQL and phpMyAdmin. Last Time... Installing Apache server Installing PHP Running basic PHP scripts on the server Not necessary.

Some Housekeeping• Add the Multi-Byte String and Mcrypt

extensions to PHP if you haven’t already.– To do this, go to Control Panel -> Uninstall

Programs, select PHP, and click “Change.” The PHP installation wizard will come up. Select the Multi-Byte String and Mcrypt extensions this time.

• Copy the file libmcrypt.dll to the Windows\System32 directory

• Restart Windows

Page 20: Installing and Using MySQL and phpMyAdmin. Last Time... Installing Apache server Installing PHP Running basic PHP scripts on the server Not necessary.

Logging in• Now go back to

localhost/phpMyAdmin/index.php• You should be able to login using username

‘root’ and the password you made when you installed MySQL.

• If you have problems on a Windows OS earlier than Windows 7, this site might help: http://www.wikihow.com/Install-phpMyAdmin-on-Your-Windows-PC

Page 21: Installing and Using MySQL and phpMyAdmin. Last Time... Installing Apache server Installing PHP Running basic PHP scripts on the server Not necessary.

phpMyAdmin Features

Create a Table

Page 22: Installing and Using MySQL and phpMyAdmin. Last Time... Installing Apache server Installing PHP Running basic PHP scripts on the server Not necessary.

Add data

Page 23: Installing and Using MySQL and phpMyAdmin. Last Time... Installing Apache server Installing PHP Running basic PHP scripts on the server Not necessary.

Browse

Page 24: Installing and Using MySQL and phpMyAdmin. Last Time... Installing Apache server Installing PHP Running basic PHP scripts on the server Not necessary.

Search

Page 25: Installing and Using MySQL and phpMyAdmin. Last Time... Installing Apache server Installing PHP Running basic PHP scripts on the server Not necessary.

Any Query

Page 26: Installing and Using MySQL and phpMyAdmin. Last Time... Installing Apache server Installing PHP Running basic PHP scripts on the server Not necessary.

So Why Learn About the Command Line?

• In some cases, using the command line is faster

• We need to know how to write MySQL queries in order to make webpages that interact with our MySQL database.

Page 27: Installing and Using MySQL and phpMyAdmin. Last Time... Installing Apache server Installing PHP Running basic PHP scripts on the server Not necessary.

• Suggestions for this week: – Install MySQL and phpMyAdmin– Play around with making databases

• Next Time:– HTML and PHP code we need to make the

database work with our website

Page 28: Installing and Using MySQL and phpMyAdmin. Last Time... Installing Apache server Installing PHP Running basic PHP scripts on the server Not necessary.

Useful Links

• MySQL download: http://dev.mysql.com/downloads/mysql/

• phpMyAdmin download: http://www.phpmyadmin.net/home_page/downloads.php

• mySQL command line commands: http://www.analysisandsolutions.com/code/mysql-tutorial.htm#creating

• Getting phpMyAdmin to work on Windows: http://www.wikihow.com/Install-phpMyAdmin-on-Your-Windows-PC