Download presentation
Presentation is loading. Please wait.
Published byClyde Neil Norman Modified over 9 years ago
1
Introduction to MySQL Ullman Chapter 4
2
Introduction MySQL most popular open-source database application Is commonly used with PHP We will learn basics of MySQL and interact with it through a server
3
Steps taken in making a database Identify needs/purpose Name the database (should be unique in the server) Decide on proper and useful identifiers (names) for the elements of the database (database, tables, columns) Names should: – only contain letters, numbers, and underscore, without space – not use SQL reserved keywords – be case sensitive – cannot be greater than ~ 64 characters (64 bytes) – Must be unique, i.e., two tables cannot have the same name, column names must be unique in each table, but same column name may appear in different tables
4
Define column types Decide on the data type for each column, which depends on the type of information to be stored; e.g., – CHAR, VARCHAR, TINYTEXT, INT, ENUM, SET, … Each has its own characters – e.g., INT[length], DECIMAL[Length, decimals] – Decide if the column is text, number, date/time, etc. – Choose on subtype for each column. For example, for email, date, and password you may choose VARCHAR, DATETIME and CHAR – Decide on the smallest possible maximum length for text columns based on the largest possible input, e.g., CHAR[30]
5
Set other properties for columns Decide whether values are required to be given for each column or not, by setting them as NOT NULL and NULL, e.g., NULL for second email address LastName CHAR[VARCHAR] NOT NULL Specify default values if needed (in case no value is entered, default is used): Gender ENUM[‘F’, ‘M’] default ‘F’ Identify the primary key – Almost always is a number and must be unique and UNSIGNED (i.e., cannot be negative) Create – Index, set to monitor the value in a column or columns (e.g., indexing a primary key) – Add keys; including primary and foreign keys Each table must only have one primary key, and one or more foreign keys to other tables. Foreign keys point to primary keys of other tables – Use AUTO_INCREMENT Uses next highest number as the id for a primary key
6
How developers access the database Need a client software to access and run the MySQL server, for example: – Mysql client Comes with the MySQL installation onto your computer Used a command-line interface (non-GUI) – phpMyAdmin client Provides a nice graphic user interface to MySQL Needs to be downloaded. Also needs PHP installation Recommended for this class. Try all-in-one PHP and MySQL installation for convenience! It is provided by a Web host if you are using hosted server (may cost a couple of bucks!) This client is accessed through a Web browser Download it from: www.phpmyadmin.netwww.phpmyadmin.net
7
Using phpMyAdmin Access it via your Web browser If you have it on your computer, the URL may be: http://localhost/phpMyAdmin/ http://localhost/phpMyAdmin/ If you are using it on a hosted site (have to pay), your host will give you the URL phpMyAdmin only works if it is correctly connected to MySQL with username/password/hostname combination Read pages 125-127 of Ullman’s book for the steps that are needed to be taken to connect to the database depending on your situation
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.