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

Chapter 17. Supporting Features Added in MySQL 5

MySQL 5.0 introduced a number of new features that calmed down a number of developers and industry observers who were claiming that MySQL was inferior to competitors' products. Views, stored procedures, triggers, a standard information_schema, and (more recently) a profiling mechanism are now present in the MySQL spectrum. These features are covered in this chapter.

Among the new features of MySQL 5.1, the ones that relate to a web interface (for example, partitioning and events) are supported in phpMyAdmin and are covered in this chapter as well.

Supporting views

MySQL 5.0 introduced support for named and updatable views (more details are available at http://dev.mysql.com/doc/refman/5.5/en/views.html). A view is a derived table (consider it a virtual table) whose definition is stored in the database. A SELECT statement done on one or more tables (or even on views), can be stored as a view and can also be queried.

Views can be used to:

  • Limit the visibility of columns (for example, do not show salary information)
  • Limit the visibility of rows (for example, do not show data for specific world regions)
  • Hide a changed table structure (so that legacy applications can continue to work)

Instead of defining cumbersome column-specific privileges on many tables, it's easier to prepare a view containing a limited set of columns from these tables. We can then grant permissions on the view as a whole.

To activate support for views on a server after an upgrade from a pre-5.0 version, the administrator has to execute the mysql_upgrade program, as described in the MySQL manual (http://dev.mysql.com/doc/refman/5.0/en/upgrading-from-previous-series.html).

Note

Each user must have the appropriate SHOW_VIEW or CREATE_VIEW privilege to be able to see or manipulate views. These privileges exist at the global (server), database, and table levels.

Creating a view implies that the user has privileges on the tables involved, or at least a privilege such as SELECT or UPDATE on all the columns mentioned in the view.

Creating a view from results

We can take advantage of phpMyAdmin's Search (at the table level) or Query (at the database level) features to build a rather complex query, execute it, and then easily create a view from the results. We will see how this is done.

We mentioned that a view can be used to limit the visibility of columns (and, in fact, of tables). Let us say that the number of pages in a book is highly classified information. We open the book table, click on Search, and choose a subset of the columns that does not include the page_count column (we might have to open the Options slider).

Creating a view from results

Clicking on Go produces a results page, where we see a CREATE VIEW link in the Query results operations section. We use this link to access the view creation panel, which already has the underlying query in the AS box. We need to choose a name for this view (here, we use book_public_info), and we can optionally set different column names for it (here, we use number, title), as shown in the following screenshot:

Creating a view from results

The other options can influence the view's behavior, and have been explained in the MySQL manual (http://dev.mysql.com/doc/refman/5.5/en/create-view.html). The LOCAL CHECK OPTION clause influences the behavior of the updateable views (this is explained in the MySQL manual at the page cited previously).

Clicking on Go generates the view we asked for. At this point, the view has been created. If we refresh our browser's page and then access the marc_book database, we will see the following screenshot:

Creating a view from results

In the main panel, we see the information on the newly-created view. The number of rows for the view currently indicates ~0 (more on this in the Controlling row counting for improved performance section, later in this chapter), and View is indicated in the Type column. There is no collation or size associated with a view.

Main panel and views

As a view has similarities with a table, its name is available along with the names of the ordinary tables. On clicking the view name, a panel similar to the one seen for tables is displayed, but with fewer menu tabs than seen in a normal table. Indeed, some operations do not make sense on a view, for example, Import. This is because a view does not actually contain data. However, other actions, such as Browse, are perfectly acceptable.

Let us browse the view shown in the following screenshot:

Main panel and views

We notice that, in the generated SQL query, we do not see our original CREATE VIEW statement. The reason is that we are selecting from the view using a SELECT statement, hiding the fact that we are pulling data from a view. However, exporting the view's structure would show how MySQL internally stored our view:

CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`%` SQL SECURITY DEFINER VIEW `book_public_info` AS
select `book`.`isbn` AS `number`,`book`.`title` AS `title` from `book`;

The main panel's menu may look similar to that of a table. However, when necessary, phpMyAdmin generates the appropriate syntax for handling views.

Note

To perform actions on existing views, a user needs to have the appropriate privilege at the view level, but not necessarily any privilege on the tables involved in this view. This is how we can achieve column and table hiding.

Controlling row counting for improved performance

phpMyAdmin has a configuration parameter, $cfg['MaxExactCountViews'], that controls the row-counting phase of phpMyAdmin. Sometimes, a view comprises many huge tables, and browsing it would make a large number of virtual rows appear. Therefore, the default value of 0 for this parameter ensures that no row counting happens for views. In this case, we will see rather strange results when browsing a view: Showing rows 0 - -1 (0 total, Query took 0.0006 sec). This is more acceptable than slowing down a server.

Nonetheless, if we prefer to see a more exact row count for views, we can put a larger value in this parameter, which acts as an upper limit for the row counting phase.