Table of Contents for
Mastering phpMyAdmin 3.4 for Effective MySQL Management

Version ebook / Retour

Cover image for bash Cookbook, 2nd Edition Mastering phpMyAdmin 3.4 for Effective MySQL Management by Marc Delisle Published by Packt Publishing, 2012
  1. Cover
  2. Mastering phpMyAdmin 3.4 for Effective MySQL Management
  3. Mastering phpMyAdmin 3.4 for Effective MySQL Management
  4. Credits
  5. About the Author
  6. About the Reviewers
  7. www.PacktPub.com
  8. Preface
  9. What you need for this book
  10. Who this book is for
  11. Conventions
  12. Reader feedback
  13. Customer support
  14. 1. Getting Started with phpMyAdmin
  15. What is phpMyAdmin?
  16. Installing phpMyAdmin
  17. Configuring phpMyAdmin
  18. Installing phpMyAdmin configuration storage
  19. Upgrading phpMyAdmin
  20. Summary
  21. 2. Configuring Authentication and Security
  22. Securing phpMyAdmin
  23. Summary
  24. 3. Over Viewing the Interface
  25. Customizing general settings
  26. Character sets and collations
  27. Navigation panel
  28. Main panel
  29. User preferences
  30. Query window
  31. Summary
  32. 4. Creating and Browsing Tables
  33. Creating our first table
  34. Inserting data manually
  35. Browse mode
  36. Profiling queries
  37. Creating an additional table
  38. Summary
  39. 5. Changing Data and Structure
  40. Changing table structure
  41. Summary
  42. 6. Exporting Structure and Data (Backup)
  43. Exporting a database
  44. Exporting a table
  45. Exporting selectively
  46. Exporting multiple databases
  47. Saving the export file on the server
  48. Memory limits
  49. Summary
  50. 7. Importing Structure and Data
  51. Importing SQL files
  52. Importing CSV files
  53. Importing other formats
  54. Reading files from a web server upload directory
  55. Displaying an upload progress bar
  56. Summary
  57. 8. Searching Data
  58. Performing a complete database search
  59. Stopping an errant query
  60. Summary
  61. 9. Performing Table and Database Operations
  62. Changing table attributes
  63. Emptying or deleting a table
  64. Renaming, moving, and copying tables
  65. Performing other table operations
  66. Multi-table operations
  67. Database operations
  68. Summary
  69. 10. Benefiting from the Relational System
  70. Defining relations with the relation view
  71. Defining relations with the Designer
  72. Benefiting from the defined relations
  73. Column commenting
  74. Summary
  75. 11. Entering SQL Statements
  76. The Query window
  77. Multi-statement queries
  78. Pretty printing (syntax highlighting)
  79. The SQL Validator
  80. Summary
  81. 12. Generating Multi-table Queries
  82. Exploring column criteria
  83. Generating automatic joins (internal relations)
  84. Executing the query
  85. The visual builder
  86. Summary
  87. 13. Synchronizing Data and Supporting Replication
  88. Supporting MySQL replication
  89. Summary
  90. 14. Using Query Bookmarks
  91. Creating bookmarks
  92. Recalling bookmarks from the bookmarks list
  93. Passing a parameter to a bookmark
  94. Summary
  95. 15. Documenting the System
  96. Generating relational schemas
  97. Summary
  98. 16. Transforming Data using MIME
  99. Enabling transformations
  100. Examples of transformations
  101. Summary
  102. 17. Supporting Features Added in MySQL 5
  103. Supporting routines—stored procedures and functions
  104. Executing code with triggers
  105. Using information_schema
  106. Partitioning
  107. Exploring the event scheduler
  108. Summary
  109. 18. Tracking Changes
  110. Prerequisites
  111. Principles
  112. Initiating tracking for one table
  113. Testing the tracking mechanism
  114. Determining tracking status
  115. Structure snapshot
  116. Exporting a version
  117. Creating a new version
  118. Deleting tracking information
  119. Summary
  120. 19. Administrating the MySQL Server
  121. Database information
  122. Server information
  123. Summary
  124. A. Troubleshooting and Support
  125. Seeking support
  126. Contributing to the project

Defining relations with the relation view

After the installation of the phpMyAdmin configuration storage, there are more options available in the Database view and the Table view. We will now examine the Relation view link in the Structure page of the Table view.

Defining relations with the relation view

This view is used to:

  • Define the relations of the current table with the other tables
  • Choose the display column

Our goal here is to create a relation between the book table (which contains the author ID) and the author table (which describes each author by an ID). We start on the Table view for the book table, go to Structure, and click on the Relation view link.

Defining internal relations

If the book table is in MyISAM format, we see the following screen (otherwise, the display would be different, as explained in the Defining foreign key relations section later):

Defining internal relations

This screen allows us to create Internal relation (stored in the pma_relation table) as MySQL itself does not have any relational notion for MyISAM tables. The empty drop-down list next to each column indicates that there are no relations (links) to any foreign table.

Defining the relation

We can relate each column of the book table to a column in another table (or in the same table because self-referencing relations are sometimes necessary). The interface finds both the unique and the non-unique keys in all the tables of the same database, and presents the keys in drop-down lists. (Creating internal relations to other databases from the interface is not currently supported.) The appropriate choice for the author_id column is to select the corresponding id column from the author table.

Defining the relation

We then click on Save, and the definition is saved in phpMyAdmin's configuration storage. To remove the relation, we would just come back to the screen, select the empty choice, and click on Save.

Defining the display column

The primary key of our author table is the id, which is a unique number that we made up for key purposes. The author's name is the natural way to refer to an author. It would be interesting to see the author's name when browsing the book table. This is the purpose of the display column. We should normally define a display column for each table that participates in a relation as a foreign table.

We will see how this information is displayed in the Benefiting from the defined relations section. We now go to the Relation view for the author table (which is the foreign table in this case) and specify the display column. We choose name as the display column and click on Save, as shown in the following screenshot:

Defining the display column

Note

phpMyAdmin offers to define only one display column for a table, and this column is used in all the relations where this table is used as a foreign table.

The definition of this relation is now done. Although we did not relate any of the columns in the author table to another table, it can be done. For example, we could have a country code in this table and could create a relation to the country code of a country table.

For now, we will see what happens if our tables are under the control of the InnoDB or PBXT storage engine.

Foreign key relations

The InnoDB and PBXT storage engines offer us a native foreign key system.

Note

At your choice, the exercises in this section can be accomplished with either InnoDB or PBXT storage engines. InnoDB has been chosen in the text.

For this exercise, our book and author tables must be under the InnoDB storage engine. We can do this from the Operations page in the Table view.

Another step is necessary in order to see the consequences of a missing index during the exercise. We go back to the Structure for the book table and remove the combined index we created on author_id and language columns.

The foreign key system in InnoDB maintains integrity between the related tables. Hence, we cannot add a non-existent author ID to the book table. In addition, actions are programmable when DELETE or UPDATE operations are performed on the master table (in our case, book).

Opening the book table on its Structure page and entering the Relation view, now displays a different page:

Foreign key relations

This page provides us the following information:

  • There is an internal relation defined for author_id to the author table.
  • No InnoDB relations are defined yet.
  • We will be able to remove the internal relation, when the same relation has been defined in InnoDB. Indeed, hovering over the question mark next to Internal relations displays the following message: An internal relation is not necessary when a corresponding FOREIGN KEY relation exists. So, it will be better to remove it.

In the possible choices for the related key, we see the keys defined in all the InnoDB tables of the same database. (Creating a cross-database relation is currently not supported in phpMyAdmin.) The keys defined in the current table are also shown, as self-referring relations are possible. Let us remove the internal relation for the author_id column and click on Save. Our goal is to add an InnoDB-type relation for the author_id column, but it's not possible as the No index defined! message appears on this line. This is because foreign key definitions in InnoDB or PBXT can be done only if both the columns have indexes.

Note

Other conditions regarding constraints are explained in the MySQL manual. Please refer to http://dev.mysql.com/doc/refman/5.1/en/innodb-foreign-key-constraints.html.

Thus, we come back to the Structure page for the book table and add an ordinary (non-unique) index to the author_id column producing the following screen:

Foreign key relations

In the Relation view, we can try again to add the relation we wanted; it works this time!

Foreign key relations

We can also set some actions with the ON DELETE and ON UPDATE options. For example, ON DELETE CASCADE would make MySQL automatically delete all the rows in the related (foreign) table when the corresponding row is deleted from the parent table. This would be useful, for example, when the parent table is invoices, and the foreign table is invoice‑items. These options are supported natively by MySQL, so deleting outside of phpMyAdmin would cause the delete cascade.

Note

If we have not done so already, we should define the display column for the author table, as explained in the Defining the display column section.

Foreign keys without phpMyAdmin configuration storage

We see the Relation view link on the Structure page of an InnoDB or PBXT table, even when the configuration storage is not installed. This would bring us to a screen where we could define the foreign keys, in this case for the book table.

Note that, if we choose this, the display column for the linked table (in this case author) cannot be defined, as it belongs to phpMyAdmin's configuration storage. Thus, we would lose the benefit of seeing the associated description of the foreign key.