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 11. Entering SQL Statements

This chapter explains how we can enter our own SQL statements (queries) into phpMyAdmin, and how we can keep a history of those queries. Traditionally, one would interact with a MySQL server via the "mysql" command-line client by entering SQL statements and watching the server's response. Official MySQL training still involves directly typing statements to such a client.

The SQL query box

phpMyAdmin allows us to accomplish many database operations via its graphical interface. However, there will be times when we have to rely on SQL query input to achieve operations that are not directly supported by the interface. Following are two examples of such queries:

SELECT department, AVG(salary) FROM employees GROUP BY department HAVING years_experience > 10;
SELECT FROM_DAYS(TO_DAYS(CURDATE()) +30);

To enter such queries, the SQL query box is available from a number of places within phpMyAdmin.

The Database view

We encounter our first SQL query box when going to the SQL menu available in the Database view.

The Database view

This box is simple—we type in some valid (hopefully) MySQL statement and click on Go. Under the query text area, there are bookmark-related choices (explained later in Chapter 14). Usually, we don't have to change the standard SQL delimiter, which is a semicolon. However, there is a Delimiter dialog in case we need it (refer to Chapter 17).

For a default query to appear in this box, we can set it with the $cfg['DefaultQueryDatabase'] configuration directive, which is empty by default. We could put a query such as SHOW TABLES FROM @DATABASE@ in this directive. The @DATABASE@ placeholder in this query would be replaced by the current database name, resulting in SHOW TABLES FROM `marc_book` in the query box.

The Table view

A slightly different box is available in the Table view of the book table from the SQL menu.

The Table view

The box already has a default query as seen in the previous screenshot. This default query is generated from the $cfg['DefaultQueryTable'] configuration directive, which contains SELECT * FROM @TABLE@ WHERE 1. Here, the @TABLE@ is replaced by the current table name. Another placeholder available in $cfg['DefaultQueryTable'] is @FIELDS@. This placeholder would be replaced by the complete column's list of this table, thus producing the following query:

SELECT `isbn`, `title`, `page_count`, `author_id`, `language`, `description`, `cover_photo`, `genre`, `date_published`, `stamp`, `some_bits` FROM `book` WHERE 1.

WHERE 1 is a condition that is always true. Therefore, the query can be executed as it is. We can replace 1 with the condition we want, or we can type a completely different query.

Because this SQL box appears in the Table view, the table name is known; therefore, phpMyAdmin shows buttons below the query box, which permit to quickly create common SQL queries which contain this table name. Most of the queries generated by these buttons contain the full column list.

The Columns selector

The Columns selector is a way to speed up query generation. By choosing a column and clicking on the arrows<<, this column name is copied at the current cursor position in the query box. Here, we select the author_id column, remove the digit 1, and click on<<. Then we add the condition = 2 as shown in the following screenshot:

The Columns selector

The Show this query here again option (checked by default) ensures that the query stays in the box after its execution if we are still on the same page. This can be seen more easily for a query like an UPDATE or DELETE, which affects a table, but does not produce a separate results page.

Clicking into the query box

We might want to change the behavior of a click inside the query box with the $cfg['TextareaAutoSelect'] configuration directive. Its default value is FALSE, which means that no automatic selection of the contents is done upon a click. Should you change this directive to TRUE, the first click inside this box will select all its contents. (This is a way to quickly copy the contents elsewhere or delete them from the box.) The next click would put the cursor at the click position.