Upload
others
View
17
Download
0
Embed Size (px)
Citation preview
Mastering phpMyAdmiri 3.4 for
Effective MySQL Management
A complete guide to getting started with
phpMyAdmin 3.4 and mastering its features
Marc Delisle
[ t]open so1 I community experience c
urcedistilled
PUBLISHING
BIRMINGHAM - MUMBAI
Table of Contents
Preface 1
Chapter 1: Getting Started with phpMyAdmin 7
PHP and MySQL: The leading open source duo 7
What is phpMyAdmin? 8
Project documentation 9
Installing phpMyAdmin 9
Required information 9
System requirements 10
Downloading the files 10
Installing on different platforms 11
Installing on a remote server using a Windows client 11
Installing on a local Linux server 11
Installing on a local Windows server (Apache, IIS) 12
Configuring phpMyAdmin 12
The config.inc.php file 12
Avoiding false error messages about permissions on config.inc.php 13
Configuration principles 13
Web-based setup script 15
Manually creating config.inc.php 20
Tips for editing config.inc.php on a Windows client 20
Description of some configuration parameters 20
PmaAbsoluteUri 21
Server-specific sections 21
Installing phpMyAdmin configuration storage 24
Goal of the configuration storage 24
Location of the configuration storage 24
Performing the installation 25
Installing for a single user 25
Installing for multiple users 27
Table of Contents_
Upgrading phpMyAdmin 28
Summary 29
Chapter 2: Configuring Authentication and Security 31
Logging in to MySQL through phpMyAdmin 31
Logging in to an account without a password 32
Authenticating a single user with config 32
Testing the MySQL connection 33
Authenticating multiple users 33
Authenticating with HTTP 33
Authenticating with cookie values 34
Authenticating with signon mode 36
Configuring for multiple server support 38Defining servers in the configuration file 38
Authenticating through an arbitrary server 39
Logging out 40
Securing phpMyAdmin 40
Protecting phpMyAdmin at directory level 40
Displaying error messages 41
Protecting with IP-based access control 41
Defining rules 42
Order of interpretation for rules 42
Blocking root access 43
Protecting in-transit data 43
Summary 44
Chapter 3: Over Viewing the Interface 45
Over viewing panels and windows 45
Login panels 45
Navigation and main panels 46Home page 46
Views 46
Query window 46
Starting page 47
Customizing general settings 47
Configuring window title 47Natural sort order for database and table names 48
Creating site-specific header and footer 48
Themes 49Configuring themes 49
Selecting themes 50
Selecting a language 50Slider 51
Restricting the list of databases 51
Table ofContents
Deactivating Ajax 52
Character sets and collations 52
Effective character sets and collations 53
Navigation panel 54
Configuring the logo 54
Database and table list 55
Light mode 55
Full mode 57
Table abridged statistics 58
Table quick-access icon 58
Nested display of tables within a database 58
Counting the number of tables 59
Choosing from the server list 59
Handling many databases or tables 60Limits on the interface 60
Improving fetch speed 61
Main panel 61
Home page 62
Database view 63
Table view 64
Server view 65
Icons for home page and menu tabs 65
Opening a new phpMyAdmin window 66
User preferences 66
Accessing user preferences 67
Possible locations for saving preferences 67
Saving in phpMyAdmin configuration storage 68
Saving in a file 68
Saving in the browser's local storage 68
Changing settings 69
Disallowing specific preferences 69
Showing developer settings 70
Query window 70
Summary 72
Chapter 4: Creating and Browsing Tables 73
Creating a database 73
No privileges 74
First database creation is authorized 74
Creating our first table 76
Choosing the columns 76
Creating a table 76
Choosing keys 79
Table ofContents
Inserting data manually 80Data entry panel tuning for CHAR and VARCHAR 82
Browse mode 83
SQL query links 83
Navigation bar 84
Query results operations 86Displaying data as a chart 86
Sorting results 87Headwords 89
Color-marking rows or columns 89
Limiting the length of each column 90
Display options 90
Browsing distinct values 91
Profiling queries 92
Creating an additional table 92
Summary 94
Chapter 5: Changing Data and Structure 95
Changing data 95
Entering edit mode 95Moving to next field with the tab key 97
Moving with arrows 97
Handling NULL values 97
Applying a function to a value 98
Duplicating rows of data 100
Multi-row editing 101
Editing the next row 102Inline row editing 102
Deleting data 103Deleting a single row 103Deleting multiple rows 104Deleting all of the rows in a table 104
Deleting all rows in multiple tables 105
Deleting tables 105
Deleting databases 106
Changing table structure 107
Adding a column 107Vertical mode 108
Editing column attribute 108TEXT column type 109BLOB (Binary Large Object) column type 110Uploading binary content 111
ENUM and SET column types 113
Table ofContents
DATE, DATETIME, and TIMESTAMP column types 115
Calendar pop up 116
TIMESTAMP option 116
Bit column type 117
Managing indexes 118
Single-column indexes 118
Multi-column indexes and index editing 120
FULLTEXT indexes 120
Optimizing indexes with EXPLAIN 121
Detecting index problems 122
Summary 123
Chapter 6; Exporting Structure and Data (Backup) 125
Dumps, backups, and exports 125
Scope of the export 126
Exporting a database 126
The Table(s) sub-panel 128
The Output sub-panel 128
File name template 128
Choosing a character set 129
Kanji support 129
Compression 129
Export formats 130
SQL 130
CSV 135
CSV for Microsoft Excel 136
PDF 137
Microsoft Word 2000 137
LaTeX 138
XML 139
Open document spreadsheet 140
Open document text 140
YAML 141
CodeGen 141
Texyltext 141
PHP array 142
MediaWiki table 142
JSON 142
Exporting a table 143
Split-file exports 143
Exporting selectively 143
Exporting partial query results 144
Exporting and checkboxes 144
Exporting multiple databases 145
Saving the export file on the server 146
User-specific save directories 147
Table ofContents
Memory limits 148
Summary 148
Chapter 7: Importing Structure and Data 149
Limits for the transfer 150
Time limits 150
Other limits 151
Handling big export files 151
Uploading into a temporary directory 152
Importing SQL files 152
Importing CSV files 154
Differences between SQL and CSV formats 154
Exporting a test file 154
CSV 154
CSV using LOAD DATA 156
Requirements 156
Using the LOAD DATA interface 157
Importing other formats 158
Open Document Spreadsheet 158
XML 159
Reading files from a web server upload directory 160
Displaying an upload progress bar 161
ConfiguringAPC 161
Summary 162
Chapter 8: Searching Data 163
Single-table searches 163
Entering the search page 163
Searching criteria by column—query by example 164Searching for empty / non-empty values 165
Producing reports with Print view 166
Searching with wildcard characters 166Case sensitivity and search 168
Combining criteria 168
Search options 168
Selecting the columns to be displayed 168
Ordering the results 169
Applying a WHERE clause 169
Avoiding repeated results 170
Performing a complete database search 171
Restricting search to a column 172
Stopping an errant query 173
Summary 173
Table of Contents
Chapter 9: Performing Table and Database Operations 175
Maintaining a table 176
Changing table attributes 177Table storage engine 177
Table comments 177
Table order 178Table collation 179Table options 180
Emptying or deleting a table 180
Renaming, moving, and copying tables 181
Appending data to a table 182
Performing other table operations 182Multi-table operations 182
Repairing an "in use" table 183Database operations 183
Renaming a database 184
Copying a database 184
Summary 184
Chapter 10: Benefiting from the Relational System 185
Relational MySQL 185InnoDB and PBXT 186
Defining relations with the relation view 186
Defining internal relations 187
Defining the relation 188
Defining the display column 188
Foreign key relations 189Foreign keys without phpMyAdmin configuration storage 192
Defining relations with the Designer 192Over viewing the interface 193
Defining relations 195Defining foreign key relations 196
Defining the display column 197
Exporting for PDF schema 197
Benefiting from the defined relations 197
Foreign key information 197
The drop-down list of foreign keys 199
The browseable foreign-table window 200
Referential integrity checks 200
Automatic updates of metadata 201
Table ofContents
Column commenting 201
Automatically migrating column comments 202
Summary 203
Chapter 11: Entering SQL Statements 205
The SQL query box 205
The Database view 206
The Table view 207
The Columns selector 208
Clicking into the query box 208
The Query window 209
Query window options 210
Session-based SQL history 210
Database-based SQL history (permanent) 210
Editing queries 211
Multi-statement queries 212
Pretty printing (syntax highlighting) 213
The SQL Validator 213
System requirements 214
Making the Validator available 214
Validator results 215
Standard-conforming queries 215
Non standard-conforming queries 216
Summary 216
Chapter 12: Generating Multi-table Queries 217
Choosing tables 218
Exploring column criteria 219
Column selector: Single column or all columns 219
Sorting columns 220
Showing a column 220
Updating the query 220
Adding conditions to the criteria box 221
Adjusting the number of criteria rows 223
Adjusting the number of criteria columns 224
Generating automatic joins (internal relations) 224
Executing the query 225
The visual builder 226
Summary 228
Chapter 13: Synchronizing Data and Supporting Replication 229
Synchronizing data and structure 229
Goals of synchronization 230
Moving between the development and production servers 230
Table of Contents
Collaboration between database designers 230
Preparing for replication 230
Over viewing the synchronization process 231
Preparing for the synchronization exercise 231
Choosing source and target servers and databases 232
Analyzing comparison results 234
Performing a complete synchronization 236
Performing a selective synchronization 236
Supporting MySQL replication 237
The Replication menu 238
Configuring replication 238
Master server configuration 239
Slave server configuration 242
Setting up a test environment 243
Controlling a slave server 244
Obtaining replication information 245
Gathering replication status 245
Replicated databases 245
Replicated tables 246
Summary 247
Chapter 14: Using Query Bookmarks 249
Comparing bookmark and query history features 250
Creating bookmarks 250
Creating a bookmark after a successful query 250
Storing a bookmark before sending a query 252
Making bookmarks public 253
The default initial query for a table 254
Multi-query bookmarks 255
Recalling bookmarks from the bookmarks list 256
Executing bookmarks 256
Manipulating bookmarks 257
Passing a parameter to a bookmark 257
Creating a parameterized bookmark 257
Passing the parameter value 258
Summary 259
Chapter 15: Documenting the System 261
Producing structure reports 261
Creating a printable report 261
The database print view 262
The selective database print view 262
The table print view 263
Preparing a complete report with the data dictionary 264
[ix]
Table of Contents
Generating relational schemas 264
Adding a third table to our model 265
Producing schema pages 266
Page planning 266
Creating a new page266
Editing a page267
Exporting a page for display 269
Changing the font in PDF schema 271
Laying out a schema with the Designer feature 272
Summary 273
Chapter 16: Transforming Data using MIME 275
Browsing data without transformations 275
Switching display options 276
Enabling transformations 276
Configuring settings for MIME columns 277
Selecting the MIME type 278
Browser transformations 278
Assigning values to transformation options 279
Requirements for image generation 279
Configuring GD2 library availability verification 280
Asserting support of JPEG and PNG libraries 280
Evaluating the impact of memory limits 281
Examples of transformations 281
Clickable thumbnail (JPEG or PNG) 281
Adding links to an image 282
Date formatting 283
Links from text 283
text/plain: link 284
text/plain: imagelink 284
Preserving the original formatting 286
Displaying parts of a text 286
Displaying a download link 286
Hexadecimal representation 287
SQL pretty printing 288
IP address 288
Transforming data via external applications 288
External application example: In-cell sort 289
Summary 290
Chapter 17: Supporting Features Added in MySQL 5 291
Supporting views 291
Creating a view from results 292
Main panel and views 294
Controlling row counting for improved performance 295
Table ofContents
Supporting routines—stored procedures and functions 295
Creating a stored procedure296
Changing the delimiter296
Entering the procedure297
Testing the procedure297
Manipulating procedures and functions 298
Manually creating a function 299
Testing the function300
Exporting stored procedures and functions 300
Executing code with triggers301
Manually creating a trigger302
Testing the trigger303
Using information_schema303
Partitioning304
Creating a table with partitions 304
Maintaining partitions305
Exporting a partition definition 305
Exploring the event scheduler306
Activating the scheduler306
Granting EVENT permission306
Creating an event306
Manipulating events307
Exporting307
Summary307
Chapter 18: Tracking Changes 309
Understanding the goals of the tracking system 309
Tracking in other software applications309
Tracking in phpMyAdmin310
Prerequisites310
Configuring a basic tracking mechanism311
Principles311
Versioning311
Taking a snapshot of the current structure 312
Understanding archiving issues 312
Initiating tracking for one table 313
Choosing the statements to be tracked 315
Testing the tracking mechanism315
Tracking report316
Determining tracking status317
Deactivating and activating tracking320
Table ofContents
Structure snapshot 320
Exporting a version 321
Creating a new version 322
Quickly accessing tracking information 323
Deleting tracking information 323
Summary 324
Chapter 19: Administrating the MySQL Server 325
Managing users and their privileges 325
The user overview 326
Exporting privileges 327
Privileges reload 328
Adding a user 328
Entering the username 329
Assigning a host value 329
Setting passwords 330
Understanding rights for database creation 330
Assigning global privileges 330
Limiting the resources used 331
Editing a user profile 331
Editing global privileges 331
Assigning database-specific privileges 332
Changing the password 334
Changing login information or copying a user 334
Removing a user 336
Database information 336
Enabling statistics 337
Sorting the statistics 337
Checking the database privileges 338
Dropping selected databases 338
Server information 339
Verifying server status 339
Server variables 341
Server processes 341
Storage engines 342
Available character sets and collations 343
Examining binary logs 343
Summary 344
Appendix: Troubleshooting and Support 345
Troubleshooting 345
System requirements 345
Verifying the base configuration 346
Solving common errors 346
Table of Contents
Seeking support 346
FAQs 347
Help forums 347
Creating a SourceForge account 347
Choosing the thread title 347
Reading the answers 347
Using the support tracker 348
Using the bug tracker 348Environment description 348
Bug description 348
Contributing to the project 349
The code base 349
Translation updates 349
Patches 349
Index 351