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

Supporting MySQL replication

In the Preparing for replication section, we saw an overview of MySQL replication. In this section, we cover the following topics:

  • How we can use phpMyAdmin to configure replication
  • How to prepare a test environment containing one master server and two slave servers
  • How to send commands to control the servers
  • How to obtain information on replication for servers, databases, and tables

phpMyAdmin's interface offers a Replication page; however, other pages contain either information about replication or links to control replication actions. We will point to each appropriate location when covering the related subject.

How to use this section depends on how many servers we have at our disposal. If we have at least two servers and want to configure them via phpMyAdmin in a master/slave relationship, we can follow the Configuring replication section. If instead we only have one server to play with, then we should take advice from the Setting up a test environment section to install many instances of the MySQL server on the same machine.

The Replication menu

In Server view, the Replication menu is only shown to privileged users, such as the MySQL root user. When a server is already configured as a master server or a slave server (or both), the Replication page is used to display status information and provide links that send commands.

Configuring replication

For this exercise, we assume that the server does not currently occupy the role of master or slave server. phpMyAdmin cannot directly configure all aspects of MySQL replication. The reason is that, contrary to manipulating database structure and data by sending queries to the MySQL server, replication configuration consists (in part) of command lines stored in a MySQL configuration file, often named my.cnf. phpMyAdmin, being a web application, does not have access to this file. This is how the MySQL server's developers intended the configuration to be—at a configuration file level.

The best that phpMyAdmin can do in this situation is to guide us by generating (on screen) the proper command lines in reaction to our preferences, then it's up to us to copy these lines where they need to go and to restart the server(s). phpMyAdmin cannot even read the current replication configuration lines; it can only deduce server status via some SHOW commands.

Let us enter the Replication menu and see what happens:

Configuring replication

Master server configuration

Now we choose to configure the server as a master by clicking on the appropriate configure link. The panel that appears gives us a thorough advice:

Master server configuration

The first paragraph confirms that this server is not configured as a master in a replication process. We want to achieve this configuration, but first we need to think about the kind of replication we want. Should all databases be replicated, except for some of them? Or do we want the opposite? A convenient drop-down list offers us these choices:

  • Replicate all databases; Ignore:
  • Ignore all databases; Replicate:

The first choice (which is the default) implies that, in general, all databases are replicated; we don't even have to enumerate them in the configuration file. In this case, the databases selector is used to specify which database we want to exclude from the replication process. Let us pick up the mysql database and see what happens in our JavaScript-enabled browser:

Master server configuration

We notice that a line appeared, stating binlog_ignore_db=mysql. This is a MySQL server instruction (not a SQL statement) that tells the server to ignore sending transactions about this database to the binary log. Let us examine the meaning of the other lines. The server-id is a unique ID generated by phpMyAdmin; each server that participates in replication must have a unique server ID. Therefore, we either track the server IDs by hand, ensuring their uniqueness, or we simply use the number randomly generated by phpMyAdmin. We also see the log-bin and log-error instructions; in fact, binary logging is mandatory in order for any replication to occur.

We could add other database names to the list by using Ctrl + Click or Command + Click, depending on our workstation's OS. However, all that phpMyAdmin does is to generate correct lines; to make them operational, we still need to follow the given advice and paste these lines at the end of the [mysqld] section of our MySQL configuration file. We should then restart the MySQL server process—the way to do this depends on our environment.

After our server has been restarted, we go back to the Replication menu; at this point, we see a different panel regarding the master:

Master server configuration

We can use the Show master status link to get some information about the master, including the current binary log name and position, and information on which databases to replicate or to ignore, as specified previously.

The Show connected slaves link would report nothing currently, as no slave is yet connected to this master.

Now would be the time to use the Add slave replication user link, because this master needs to have a separate account dedicated to replication. The slaves will use this account created on the master to connect to it. Clicking on this link displays the following panel, in which a user account, replic, is being created with a password of our choosing:

Master server configuration

After clicking on Go, phpMyAdmin takes care of creating this user with the correct permissions set.

Slave server configuration

Now, on the machine that will act as a slave server in the replication process, we start phpMyAdmin. In the Replication menu, we click on configure in the following dialog:

Slave server configuration

The slave server configuration panel appears, as shown in the following screenshot:

Slave server configuration

As with the master configuration, we get a suggestion about having a unique server ID in the configuration file for the slave, and we should follow this advice.

In this panel, we enter the username and password of the dedicated replication account we created on the master. We also have to indicate the hostname and port number corresponding to the master server. After filling this panel and clicking on Go, phpMyAdmin sends the appropriate CHANGE MASTER command to the slave, which puts this server in slave mode.

Setting up a test environment

The replication process occurs between at least two instances of the MySQL server. In production, this normally implies a minimum of two physical servers to procure these benefits:

  • Better performance
  • Increased redundancy

However, due to MySQL's configurable port number (the default being 3306), data directory, and socket, it's possible to have more than one MySQL instance on the same server. This setup can be configured manually, or via an installation system such as the MySQL Sandbox. This is an open source project located at http://mysqlsandbox.net. With this tool, we can set up one or many MySQL servers very quickly. By using the powerful make_replication_sandbox Linux shell command, we can install an environment that consists of one master server and two slave servers. Each server can be started or stopped individually.

The following exercises assume that the MySQL Sandbox has been installed on your server and that phpMyAdmin's config.inc.php contains a reference to these Sandbox servers, as shown in the following code block (please adjust the socket names to your own environment):

$i++;
$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['socket'] = '/tmp/mysql_sandbox25562.sock';
$cfg['Servers'][$i]['verbose'] = 'master';
$i++;
$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['socket'] = '/tmp/mysql_sandbox25563.sock';
$cfg['Servers'][$i]['verbose'] = 'slave1';
$i++;
$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['socket'] = '/tmp/mysql_sandbox25564.sock';
$cfg['Servers'][$i]['verbose'] = 'slave2';

Here, we use the $cfg['Servers'][$i]['verbose'] directive to give a unique name to each instance, as the real server name is localhost for all of these instances. Each Sandbox server initially contains two databases: mysql and test.

Controlling a slave server

Here we will assume that the Sandbox testing environment has been set. However, the explanations are useful for all situations in which we have a slave server. After connecting to a slave and once again opening the Replication menu, we see:

Controlling a slave server

The following options are available:

  • The See slave status table link permits us to receive information about all the system variables related to replication for this slave server.
  • The Control slave: link reveals more options; some of them can toggle between the stop and start condition:
    • The Full stop option is used to stop both the IO thread (the part of the MySQL server responsible for receiving updates from the master and writing them to the slave's relay log) and the SQL thread (which reads the updates from the relay log and executes them)
    • The Reset slave option stops the slave, sends a RESET SLAVE command that causes it to forget its replication position in the master's binary log, and then restarts the slave
    • The SQL Thread Stop only option and IO Thread Stop only option are used to stop just the respective thread
  • The Error management: link permits to tell the slave server to skip some of the events (updates) sent from the master. For more details, please refer to http://dev.mysql.com/doc/refman/5.1/en/set-global-sql-slave-skip-counter.html.
  • The Change or reconfigure master server link could be used to specify that this slave server should now receive updates from a different master.

Obtaining replication information

Apart from the Replication menu, other screens in phpMyAdmin inform us about replication-related items. These screens are not found with the other replication dialogs; rather they are scattered on various pages, where they display replication information in the context of the respective pages.

Gathering replication status

By entering the Status panel in Server view, we first get a brief message, for example:

"This MySQL server works as master in replication process. For further information about replication status on the server, please visit the replication section."

There are a few Replication links on this page that show us the status variables of either the master or slave servers, and some links to get information about how many slave hosts are connected and the status of replication in general.

Replicated databases

On the master server, having a look at the Databases menu in Server view shows us that some databases can potentially be replicated, with a green checkmark in the Master replication column:

Replicated databases

This is because this server is configured with a binary log and these databases are not excluded from replication.

As we have the following line of code in the [mysqld] section within the master's configuration file, we can exclude from the binary log all transactions that affect the mysql database:

binlog_ignore_db=mysql

Therefore, the output of the Databases page shows a red icon next to the mysql database.

If this is a slave server, a Server replication column is shown.

Tip

Note that a slave server can itself have a binary log; therefore, in this case, both Master replication and Slave replication columns are shown. This means that this slave could in turn be a master server for another slave server.

Replicated tables

Let us suppose that on the master server, we create a table named employee in the test database. At this point, replication does its magic and we can have a look at the test database on a slave server:

Replicated tables

Here, the Replication column is shown as a reminder. We should not modify this table on the slave server directly, because its existence is for replication purpose only. If we decide to alter it directly, our changes will be done only in this table, introducing inconsistencies between the master and this slave, which is not a good idea.