Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Intro to MySQL.

Slides:



Advertisements
Similar presentations
Copyright © 2003 Pearson Education, Inc. Slide 8-1 The Web Wizards Guide to PHP by David Lash.
Advertisements

Session 2Introduction to Database Technology Data Types and Table Creation.
MySQL Access Privilege System
CC SQL Utilities.
MySQL. To start go to Login details: login: labuser password:macimd15 – There.
2010/11 : [1]Building Web Applications using MySQL and PHP (W1)MySQL Recap.
Day 3 - Basics of MySQL What is MySQL What is MySQL How to make basic tables How to make basic tables Simple MySQL commands. Simple MySQL commands.
Let’s try Oracle. Accessing Oracle The Oracle system, like the SQL Server system, is client / server. For SQL Server, –the client is the Query Analyser.
Quick-and-dirty.  Commands end in a semi-colon ◦ If you forget, another prompt line shows up  Either continue the command or…  End it with a semi-colon.
CIT 381 Data Types - data types - create table statement - constraints.
Introduction to Structured Query Language (SQL)
A Guide to SQL, Seventh Edition. Objectives Understand the concepts and terminology associated with relational databases Create and run SQL commands in.
DT211 Stage 2 Databases Lab 1. Get to know SQL Server SQL server has 2 parts: –A client, running on your machine, in the lab. You access the database.
30-Jun-15 SQL A Brief Introduction. SQL SQL is Structured Query Language Some people pronounce SQL as “sequel” Other people insist that only “ess-cue-ell”
Introduction to Structured Query Language (SQL)
Creating Database Tables CS 320. Review: Levels of data models 1. Conceptual: describes WHAT data the system contains 2. Logical: describes HOW the database.
A Guide to MySQL 3. 2 Objectives Start MySQL and learn how to use the MySQL Reference Manual Create a database Change (activate) a database Create tables.
Structured Query Language SQL: An Introduction. SQL (Pronounced S.Q.L) The standard user and application program interface to a relational database is.
MySql In Action Step by step method to create your own database.
A Guide to SQL, Eighth Edition Chapter Three Creating Tables.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
Chapter 5 Introduction to SQL. Structured Query Language = the “programming language” for relational databases SQL is a nonprocedural language = the user.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Cookies & Sessions.
INTERNET APPLICATION DEVELOPMENT For More visit:
ASP.NET Programming with C# and SQL Server First Edition
Copyright © 2003 Pearson Education, Inc. Slide 8-1 The Web Wizard’s Guide to PHP by David Lash.
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor Ms. Arwa.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
Week Four CIT 354 Internet II. 2 Objectives Uploading Files to Your Web Site Establishing a Connection Creating a Database Table Common Programming Errors.
Chapter 7 Working with Databases and MySQL PHP Programming with MySQL 2 nd Edition.
Chapter 7 Working with Databases and MySQL PHP Programming with MySQL 2 nd Edition.
CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP username Followed Not case sensitive Initial.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
Chapter 4 Introduction to MySQL. MySQL “the world’s most popular open-source database application” “commonly used with PHP”
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
LIS651 lecture 6 mySQL Thomas Krichel
Introduction to MySQL Lab no. 10 Advance Database Management System.
Introduction to Internet Databases MySQL Database System Database Systems.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
CSC 2720 Building Web Applications Database and SQL.
NMED 3850 A Advanced Online Design January 12, 2010 V. Mahadevan.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting MySQL – Selecting Data.
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Chapter 5 MYSQL Database. Introduction to MYSQL MySQL is the world's most popular open-source database. Open source means that the source code, the programming.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP & MySQL.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting MySQL – Inserting Data.
A Guide to MySQL 3. 2 Introduction  Structured Query Language (SQL): Popular and widely used language for retrieving and manipulating database data Developed.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
What’s a database? Data stored in a structured format that lends itself to easy manipulation and recall.
Sql DDL queries CS 260 Database Systems.
>> Introduction to MySQL. Introduction Structured Query Language (SQL) – Standard Database Language – Manage Data in a DBMS (Database Management System)
Class 3Intro to Databases Class 4 Simple Example of a Database We’re going to build a simple example of a database, which will allow us to register users.
Introduction to MySQL Ullman Chapter 4. Introduction MySQL most popular open-source database application Is commonly used with PHP We will learn basics.
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
3 A Guide to MySQL.
Chapter 5 Introduction to SQL.
SQL and SQL*Plus Interaction
Open Source Server Side Scripting Permissions & Users
Database application MySQL Database and PhpMyAdmin
ISC440: Web Programming 2 Server-side Scripting PHP 3
Chapter 7 Working with Databases and MySQL
Chapter 8 Working with Databases and MySQL
PHPMyAdmin.
Intro to Relational Databases
Tutorial 6 PHP & MySQL Li Xu
Chapter 4 Introduction to MySQL.
MySQL Database System Installation Overview SQL summary
MySQL Database System Installation Overview SQL summary
Presentation transcript:

Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Intro to MySQL

Open Source Server Side Scripting 2 ECA 236 test MySQL  to test from the command line on Windows platform, change the directory: c:\mysql\bin  or change the PATH  start the MySQL server mysqld  or use the Windows utility, winmysqladmin, to start the MySQL server

Open Source Server Side Scripting 3 ECA 236 test MySQL cont …  to test the installation, at the command line type: mysqlshow # returns a list of databases mysqlshow mysql # returns the tables in the database named mysql mysqladmin version status proc # returns current status / information re: MySQL

Open Source Server Side Scripting 4 ECA 236 MySQL server  through administration of the MySQL server we can:  create databases  drop databases  create users  set permissions  etc

Open Source Server Side Scripting 5 ECA 236 MySQL privileges  MySQL uses a system of privileges to allow users access to do certain things  we do not want all users to have the same level of privileges  regular users should not have the power to create, delete, or change the structure of a database, or even use any other database on the server

Open Source Server Side Scripting 6 ECA 236 MySQL configuration  the default configuration of MySQL is not ideal  to make MySQL more secure we will  set a password for the root user  delete the anonymous user

Open Source Server Side Scripting 7 ECA 236 root user  MySQL comes with a superuser account named root, which has all the possible privileges to administer the server  by default, root does not have an associated password  without a password, virtually anyone could log on to the server as root and use administrative privileges

Open Source Server Side Scripting 8 ECA 236 root user cont …  when signing in at the command line as a particular user we use a flag ( -u ) followed by the name of the user  without a password, anyone can log on as root  remember, the mysql monitor is a way to interact with the MySQL server through a command line interface mysql -u root

Open Source Server Side Scripting 9 ECA 236 setting the root password  at the mysql prompt type:  remember, all commands must end with a semicolon  SQL commands, which we will look at shortly, are generally written in upper case to differentiate them from database, table, and column names use mysql; UPDATE user SET password=PASSWORD(‘welcome’) WHERE user=‘root’; FLUSH PRIVILEGES;

Open Source Server Side Scripting 10 ECA 236 setting the root password cont …  new versions of MySQL (4.1 and up) have changed the passwords from 16 to 32 bits  incompatible with older versions of PHP  older versions of PHP use 16 bit passwords  use MySQL OLD_PASSWORD( ) function use mysql; UPDATE user SET password=OLD_PASSWORD(‘welcome’) WHERE user=‘root’; FLUSH PRIVILEGES;

Open Source Server Side Scripting 11 ECA 236 setting the root password cont …  new versions of MySQL (4.1 and up) have changed the passwords from 16 to 32 bits  use OLD_PASSWORD if you get an error similar to: Client does not support authentication protocol requested by server; consider upgrading MySQL client …

Open Source Server Side Scripting 12 ECA 236 setting the root password cont …  the use keyword tells MySQL which database we will be working with  at the time of installation, two databases are created  mysql  contains grant tables, used to store information about privileges  test  a simple test database use mysql;

Open Source Server Side Scripting 13 ECA 236 setting the root password cont …  passwords should not be saved as unencrypted text  UPDATE is a SQL command which allows us to modify data in a table  user is a table in the mysql database which stores information about users, including associated passwords UPDATE user SET password=PASSWORD(‘welcome’) WHERE user=‘root’;

Open Source Server Side Scripting 14 ECA 236 setting the root password cont …  PASSWORD( ) is a function to encrypt the actual string password  encrypted string is always 16 characters long  PASSWORD( ) uses a one-way encryption algorithm, meaning there is no way to unencrypt it  output of PASSWORD( ) is not arbitrary – the same word will result in the same encrypted string each time  EG, “welcome” will be encrypted as 4326ef3a2d0d0116 UPDATE user SET password=PASSWORD(‘welcome’) WHERE user=‘root’;

Open Source Server Side Scripting 15 ECA 236 setting the root password cont …  WHERE limits which records to return  conditional operators such as the equal sign are used to create a condition  here we are testing to make sure the user’s name is root  other conditional operators include > < BETWEEN NOT BETWEEN etc UPDATE user SET password=PASSWORD(‘welcome’) WHERE user=‘root’;

Open Source Server Side Scripting 16 ECA 236 setting the root password cont …  after you make certain changes to the grant tables using UPDATE, the changes do not automatically take effect  FLUSH PRIVILEGES lets the server know that changes have taken place  it resets the list of acceptable users and their privileges FLUSH PRIVILEGES;

Open Source Server Side Scripting 17 ECA 236 setting the root password cont …  from this point on, tasks that previously did not require the use of a password will not work without one  administrative tasks with mysqladmin  signing on to mysql monitor  include the -u flag followed by the username  include the -p flag to indicate a password is being used mysql -u root -p

Open Source Server Side Scripting 18 ECA 236 setting the root password cont …  do not type the actual password after the -p flag, although doing so is possible  MySQL will prompt you for a password, which will be overwritten by asterisks bin>mysql -u root -p Enter password: *******

Open Source Server Side Scripting 19 ECA 236 deleting anonymous user  when MySQL is installed, an anonymous user is created  the anonymous user can access the system without supplying a username or password mysql>DELETE FROM user WHERE user=‘’; DELETE command two single quotes user is equal to anonymous FROM user table

Open Source Server Side Scripting 20 ECA 236 planning your database  plan your database  what tables will the database contain?  what field will each table contain?  what type of information will each field contain?  we will create a database named sitename which contains:  user ID  last name  first name  address  password  registration date

Open Source Server Side Scripting 21 ECA 236 MySQL naming rules  when naming fields the following rules apply:  you must use names containing  alphanumeric characters  underscore  no spaces  correct:  bob_inventory  incorrect  bob’s inventory

Open Source Server Side Scripting 22 ECA 236 data types  when creating the database, MySQL requires that you define a data type for each field  MySQL’s three main categories of data:  Text  Numbers  Date & Times  choosing data type determines what kind of data can be stored, and overall performance of database

Open Source Server Side Scripting 23 ECA 236 text data types TypeDescription CHAR (length)0 – 255 characters long VARCHAR (length)0 – 255 characters long TINYTEXTmax length of 255 characters TEXTmax length of characters MEDIUMTEXTmax length of 16+ million characters LONGTEXTmax length of 4+ billion characters CHAR and VARCHAR can take a (length) attribute, limiting their total size – length is optional for CHAR, required for VARCHAR

Open Source Server Side Scripting 24 ECA 236 CHAR vs VARCHAR  both store can be set to a maximum length  CHAR will always be stored as a string the length of your maximum length. Spaces are used to pad any string that is less than the max  VARCHAR will be stored as a string which is only as long as the string itself

Open Source Server Side Scripting 25 ECA 236 number data types TypeDescription TINYINT [length]-128 to 127, or 0 to 255 unsigned SMALLINT [length] to 32767, or 0 to unsigned MEDIUMINT [length] to , or 0 to unsigned INT [length]-2+ billion to 2+ billion, or 0 to 4+ billion unsigned BIGINT [length]very large FLOATa small number with a floating decimal point DOUBLE [length] [decimals]a large number with a floating decimal point DECIMAL [length] [decimals]a DOUBLE stored as a string

Open Source Server Side Scripting 26 ECA 236 number data types cont …  many number data types take optional [length]  SIGNED  able to take negative values  UNSIGNED  only positive values and zero  ZEROFILL  extra spaces padded with zeros, automatically unsigned

Open Source Server Side Scripting 27 ECA 236 date data types TypeDescription DATEYYYY-MM-DD DATETIMEYYYY-MM-DD HH:MM::SS TIMESTAMPYYYYMMDDHHMMSS ( ends in the year 2037 ) TIMEHH:MM:SS for more information about date data types, visit the MySQL manual,

Open Source Server Side Scripting 28 ECA 236 two special types TypeDescription ENUMa string object that can only have one value, chosen from a list of several thousand values SETallows for several values, up to 64

Open Source Server Side Scripting 29 ECA 236 NULL and NOT NULL  NULL means the field has no value, not even an empty string  NULL  no value is required, field can be empty  NOT NULL  value is required, field cannot be empty  default values  use default followed by the default value

Open Source Server Side Scripting 30 ECA 236 designing users for sitename  the database sitename will contain one table named users, which contains the following fields users Table Column nameExample user_id13 first_nameJosie last_namePackard passwordbob registration_date :47:29

Open Source Server Side Scripting 31 ECA 236 designing users for sitename cont…  identify whether those fields should be a text, number, or date data type users Table Column nameExample user_idnumber first_nametext last_nametext text passwordtext registration_datedate

Open Source Server Side Scripting 32 ECA 236 designing users for sitename cont…  choose a subtype for each field users Table Column nameExample user_idMEDIUMINT first_nameVARCHAR last_nameVARCHAR VARCHAR passwordCHAR registration_dateDATETIME

Open Source Server Side Scripting 33 ECA 236 designing users for sitename cont…  set maximum length and other attributes for each column users Table Column nameExample user_idMEDIUMINT UNSIGNED NOT NULL first_nameVARCHAR(15) NOT NULL last_nameVARCHAR(30) NOT NULL VARCHAR(40) passwordCHAR(16) NOT NULL registration_dateDATETIME NOT NULL

Open Source Server Side Scripting 34 ECA 236 primary key  to be a PRIMARY KEY a column must meet three conditions:  it must always contain a value ( NOT NULL )  the value must never change  the value must be unique for each record  the PRIMARY KEY for the users table will be the field user_id

Open Source Server Side Scripting 35 ECA 236 auto increment  to insure that each record in user_id is unique, use the AUTO_INCREMENT statement  every time a record is added, the value in user_id will automatically be incremented

Open Source Server Side Scripting 36 ECA 236 create sitename  start MySQL  sign onto the mysql monitor as the root user  create the sitename database  use the sitename database CREATE DATABASE sitename; USE sitename;

Open Source Server Side Scripting 37 ECA 236 creating a table  the CREATE statement is also used to create a table, once we indicate which database to use  syntax to create a table:  after naming the table, name and define each column in order, within parentheses  separate columns/descriptions with a comma CREATE TABLE tablename (column1name description, column2name description, …);

Open Source Server Side Scripting 38 ECA 236 create table users  syntax: CREATE TABLE users ( user_id MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT, first_name VARCHAR(15) NOT NULL, last_name VARCHAR(30) NOT NULL, VARCHAR(40), password CHAR(16) NOT NULL, registration_date DATETIME NOT NULL, PRIMARY KEY (user_id) );

Open Source Server Side Scripting 39 ECA 236 confirm table creation  confirm the existence of the table:  confirm the creation of the columns: SHOW TABLES; SHOW COLUMNS FROM users; ~~~ or ~~~ DESCRIBE users;

Open Source Server Side Scripting 40 ECA 236 backing up a database  mysqldump  will back up tables and their structure  run directly from command line  dump file to the screen: mysqldump -u root -p sitename

Open Source Server Side Scripting 41 ECA 236 backing up a database cont …  mysqldump  create an output file  contains SQL commands to create the table  contains data to populate the table mysqldump -u root -p sitename > c:/data/mydump.sql

Open Source Server Side Scripting 42 ECA 236 backing up a database cont …  mysqldump  read the file back into MySQL using the syntax:  review MySQL Manual for a long list of options to use with mysqldump mysql -u root -p sitename < c:/data/mydump.sql