MySQL

  • Basics
  • Quick reference
  • Examples
  • phpMyAdmin

MySQL (prnounced either My S-Q-L or My Sequel) is an open source relational database management system based on SQL (structure query language) for modifying information in the database.

Used in conjuntion with a scripting language like PHP to access information in the database depending on user input, today's web pages provide content tailored to the viewer's interests. Because both MySQL and PHP are both open source (free to download and use), the PHP/MySQL combination has become a popular choice for database-driven websites.

      1. ----building...

      1. 1 - Download the latest Generally Available(GA) release of the MySQL Community Server from , using appropriate links to the package format installer for your version of Mac OS. Note: If you have an Intel chip, use the x86 link; all others use PowerPC.
        2 - On your computer, double-click the downloaded file to mount it.
        3 - Open the disk image and double-click the mysql package to begin the installation process. If upgrading MySQL from a previous version, be certain to stop the existing MySQL server before installing the new version.
        4 - Follow through the installation process.
        5 - Install the MySQL preference pane by double-clicking the MySQL.prefPane file in the disk image to easily start and stop MySQL.
        6 - Open System Preferences and click MySQL, under Other.
        The new MySQL preferences pane will be available the next time you open the System Preferences. If System Preferences was open when you installed the MySQL pane, you’ll need to quit and reopen System Preferences.
        7 - Use the new pane to start and stop the MySQL.
        8 - Immediately set a password for the root MySQL user.
        To assign a password to the root user:
        1. Log in to your system from a commandline interface (Terminal application).
        2. Move to the mysql/bin directory.
        Type command:
        cd /usr/local/mysql/bin
        3. Passwords are case-sensitive. Enter the following, replacing thepassword with the password you want to use:
        ./mysqladmin -u root password
        ➝ thepassword

        ----building...

      1. ----building...

      1. MySQL uses all the standard ANSI SQL numeric data types, so if you're coming to MySQL from a different database system, these definitions will look familiar to you. The following list shows the common numeric data types and their descriptions.
        The terms signed and unsigned will be used in the list of numeric data types. Referencing basic algebra, remember that a signed integer is a positive or negative integer, whereas an unsigned integer is a non-negative integer.
      2. INT
      3. A normal-sized integer that can be signed or unsigned. If signed, the allowable range is from –2147483648 to 2147483647. If unsigned, the allowable range is from 0 to 4294967295. You can specify a width of up to 11 digits.

      4. TINYINT
      5. A very small integer that can be signed or unsigned. If signed, the allowable range is from –128 to 127. If unsigned, the allowable range is from 0 to 255. You can specify a width of up to 4 digits.

      6. SMALLINT
      7. A small integer that can be signed or unsigned. If signed, the allowable range is from –32768 to 32767. If unsigned, the allowable range is from 0 to 65535. You can specify a width of up to 5 digits.

      8. MEDIUMINT
      9. A medium-sized integer that can be signed or unsigned. If signed, the allowable range is from –8388608 to 8388607. If unsigned, the allowable range is from 0 to 16777215. You can specify a width of up to 9 digits.

      10. BIGINT
      11. A large integer that can be signed or unsigned. If signed, the allowable range is from –9223372036854775808 to 9223372036854775807. If unsigned, the allowable range is from 0 to 18446744073709551615. You can specify a width of up to 11 digits.

      12. FLOAT(M,D)
      13. A floating-point number that cannot be unsigned. You can define the display length (M) and the number of decimals (D). This is not required and will default to 10,2, where 2 is the number of decimals and 10 is the total number of digits (including decimals). Decimal precision can go to 24 places for a FLOAT.

      14. DOUBLE(M,D)
      15. A double precision floating-point number that cannot be unsigned. You can define the display length (M) and the number of decimals (D). This is not required and will default to 16,4, where 4 is the number of decimals. Decimal precision can go to 53 places for a DOUBLE. REAL is a synonym for DOUBLE.

      16. DECIMAL(M,D)
      17. An unpacked floating-point number that cannot be unsigned. In unpacked decimals, each decimal corresponds to one byte. Defining the display length (M) and the number of decimals (D) is required. NUMERIC is a synonym for DECIMAL.

      1. MySQL has several data types available for storing dates and times, and these data types are flexible in their input. This means that you can enter dates that are not really days, such as February 30—February has only 28 or 29 days, never 30. Also, you can store dates with missing information. If you know that someone was born sometime in November of 1980, you can use 1980-11-00, where "00" represents the unknown day.

        The flexibility of MySQL's date and time types also means that the responsibility for date checking falls on the application developer. MySQL checks only two elements for validity: that the month is between 0 and 12 and the day is between 0 and 31. MySQL does not automatically verify that the 30th day of the second month (February 30th) is a valid date.

      2. DATE
      3. A date in YYYY-MM-DD format, between 1000-01-01 and 9999-12-31. For example, December 30th, 1973 would be stored as 1973-12-30.

      4. DATETIME
      5. A date and time combination in YYYY-MM-DD HH:MM:SS format, between 1000-01-01 00:00:00 and 9999-12-31 23:59:59. For example, 3:30 in the afternoon on December 30th, 1973 would be stored as 1973-12-30 15:30:00.

      6. TIMESTAMP
      7. A timestamp between midnight, January 1, 1970 and sometime in 2037. You can define multiple lengths to the TIMESTAMP field, which directly correlates to what is stored in it. The default length for TIMESTAMP is 14, which stores YYYYMMDDHHMMSS. This looks like the previous DATETIME format, only without the hyphens between numbers; 3:30 in the afternoon on December 30th, 1973 would be stored as 19731230153000. Other definitions of TIMESTAMP are 12 (YYMMDDHHMMSS), 8 (YYYYMMDD), and 6 (YYMMDD).

      8. TIME
      9. Stores the time in HH:MM:SS format.

      10. YEAR(M)
      11. Stores a year in 2 digit or 4 digit format. If the length is specified as 2 (for example, YEAR(2)), YEAR can be 1970 to 2069 (70 to 69). If the length is specified as 4, YEAR can be 1901 to 2155. The default length is 4.


      1. Most data stored will be in string format. This list describes the common string data types in MySQL.

      2. CHAR(M)
      3. A fixed-length string between 1 and 255 characters in length (for example, CHAR(5)), right-padded with spaces to the specified length when stored. Defining a length is not required, but the default is 1.

      4. BLOB or TEXT
      5. A field with a maximum length of 65535 characters. BLOBs are "Binary Large Objects" and are used to store large amounts of binary data, such as images or other types of files. Fields defined as TEXT also hold large amounts of data; the difference between the two is that sorts and comparisons on stored data are case sensitive on BLOBs and are not case sensitive in TEXT fields. You do not specify a length with BLOB or TEXT.

      6. TINYBLOB or TINYTEXT
      7. A BLOB or TEXT column with a maximum length of 255 characters. You do not specify a length with TINYBLOB or TINYTEXT.

      8. MEDIUMBLOB or MEDIUMTEXT
      9. A BLOB or TEXT column with a maximum length of 16777215 characters. You do not specify a length with MEDIUMBLOB or MEDIUMTEXT.

      10. LONGBLOB or LONGTEXT
      11. A BLOB or TEXT column with a maximum length of 4294967295 characters. You do not specify a length with LONGBLOB or LONGTEXT.

      12. ENUM
      13. An enumeration, which is a list. When defining an ENUM, you are creating a list of items from which the value must be selected (or it can be NULL). For example, if you wanted your field to contain either "A" or "B" or "C", you would define your ENUM as ENUM ('A', 'B', 'C') and only those values (or NULL) could ever populate that field. ENUMs can have 65535 different values.

      14. SET
      15. The SET type is similar to ENUM in that it is defined as a list. However, the SET type is stored as a full value rather than an index of a value, as with ENUMs.

Note that commands may also be typed into the SQL tab of phpMyAdmin.

Create database
create database [databasename];

Switch to a database
use [db name];

Delete a database
drop database [database name];

Show all databases
show databases;

Switch to a database
use [db name];

Show all tables in a database
show tables;

View a table's field formats
describe [table name];

Delete a table
drop table [table name];

View columns/column info from a table
show columns from [table name];

Show all data in a table
SELECT * FROM [table name];

Show all data from a table that matches the keyword
SELECT * FROM [table name] WHERE [field name] = "keyword";

Example: Select all records from table named pets that contain the record ferrets
SELECT * FROM pets WHERE type = "ferrets";

Show all data from a table in which field1=keyword AND field2=keyword2
SELECT * FROM [table name] WHERE field1 = "keyword" AND field2 = 'keyword2';

Example: Select all records from table named pets that contain ferrets AND also male.
SELECT * FROM pets WHERE type = "ferrets" AND sex = 'male';

SHOW records from specific columns sorted in ascending order based on data in column 1
SELECT [column1],[column2] FROM [table name] ORDER BY [column1] ASC;

SHOW records from specific columns sorted in descending order based on data in column 1
SELECT [column1],[column2] FROM [table name] ORDER BY [column1] DESC;

Add a new column to a table
alter table [table name] add column [new column name] variable-type (size);

Example: Add a column named endangered to a table named animals with a variable type of char with a record size of 20
alter table animals add column endangered char (20);

Increase a column size
alter table [table name] modify [column name] VARCHAR(size);

Add a unique (avoiding duplicates) column to a table
alter table [table name] add unique ([column name]);

Count number of rows in a table
SELECT COUNT(*) FROM [table name];





Please feel welcome to Contact Gtekk with questions.

Welcome to Gtekk.

This section will contain examples with step-by-step instruction.

As established users know, all features of Gtekk are being upgraded to our new format.
Apologies for the delay. These placeholder pages will be updated with the original content one section at a time.
Please feel welcome to Contact Gtekk with questions in the meantime.

Welcome to Gtekk.

A MySQL help file without phpMyAdmin would be lacking. Screenshots and examples of managing a MySQL database using PHPMyAdmin.

As established users know, all features of Gtekk are being upgraded to our new format.
Apologies for the delay. These placeholder pages will be updated with the original content one section at a time.
Please feel welcome to Contact Gtekk with questions in the meantime.



Resources

See all links
Paragon IT Consultants

Javascript Kit - Free scripts
Adobe tutorials