使用 phpMyAdmin

6.1 I can’t insert new rows into a table / I can’t create a table - MySQL brings up a SQL error.

Examine the SQL error with care. Often the problem is caused by specifying a wrong column-type. Common errors include:

  • Using VARCHAR without a size argument
  • Using TEXT or BLOB with a size argument

同时,请参考 MySQL 手册中语法一章确定你的语法都正确。

6.2 When I create a table, I set an index for two columns and phpMyAdmin generates only one index with those two columns.

这是一种创建多字段索引的方法。如果你需要两个索引,在建表时先设置一个,保存,然后显示数据表属性并点击索引链接来创建另一个索引。

6.3 How can I insert a null value into my table?

Since version 2.2.3, you have a checkbox for each column that can be null. Before 2.2.3, you had to enter “null”, without the quotes, as the column’s value. Since version 2.5.5, you have to use the checkbox to get a real NULL value, so if you enter “NULL” this means you want a literal NULL in the column, and not a NULL value (this works in PHP4).

6.4 How can I backup my database or table?

Click on a database or table name in the navigation panel, the properties will be displayed. Then on the menu, click “Export”, you can dump the structure, the data, or both. This will generate standard SQL statements that can be used to recreate your database/table. You will need to choose “Save as file”, so that phpMyAdmin can transmit the resulting dump to your station. Depending on your PHP configuration, you will see options to compress the dump. See also the $cfg['ExecTimeLimit'] configuration variable. For additional help on this subject, look for the word “dump” in this document.

6.5 How can I restore (upload) my database or table using a dump? How can I run a “.sql” file?

Click on a database name in the navigation panel, the properties will be displayed. Select “Import” from the list of tabs in the right–hand frame (or “SQL” if your phpMyAdmin version is previous to 2.7.0). In the “Location of the text file” section, type in the path to your dump filename, or use the Browse button. Then click Go. With version 2.7.0, the import engine has been re–written, if possible it is suggested that you upgrade to take advantage of the new features. For additional help on this subject, look for the word “upload” in this document.

Note: For errors while importing of dumps exported from older MySQL versions to newer MySQL versions, please check 6.41 I get import errors while importing the dumps exported from older MySQL versions (pre-5.7.6) into newer MySQL versions (5.7.7+), but they work fine when imported back on same older versions ?.

6.6 How can I use the relation table in Query-by-example?

Here is an example with the tables persons, towns and countries, all located in the database “mydb”. If you don’t have a pma__relation table, create it as explained in the configuration section. Then create the example tables:

  1. CREATE TABLE REL_countries (
  2. country_code char(1) NOT NULL default '',
  3. description varchar(10) NOT NULL default '',
  4. PRIMARY KEY (country_code)
  5. ) ENGINE=MyISAM;
  6. INSERT INTO REL_countries VALUES ('C', 'Canada');
  7. CREATE TABLE REL_persons (
  8. id tinyint(4) NOT NULL auto_increment,
  9. person_name varchar(32) NOT NULL default '',
  10. town_code varchar(5) default '0',
  11. country_code char(1) NOT NULL default '',
  12. PRIMARY KEY (id)
  13. ) ENGINE=MyISAM;
  14. INSERT INTO REL_persons VALUES (11, 'Marc', 'S', 'C');
  15. INSERT INTO REL_persons VALUES (15, 'Paul', 'S', 'C');
  16. CREATE TABLE REL_towns (
  17. town_code varchar(5) NOT NULL default '0',
  18. description varchar(30) NOT NULL default '',
  19. PRIMARY KEY (town_code)
  20. ) ENGINE=MyISAM;
  21. INSERT INTO REL_towns VALUES ('S', 'Sherbrooke');
  22. INSERT INTO REL_towns VALUES ('M', 'Montréal');

设置对应连接并显示信息:

  • on table “REL_persons” click Structure, then Relation view
  • for “town_code”, choose from dropdowns, “mydb”, “REL_towns”, “code” for foreign database, table and column respectively
  • for “country_code”, choose from dropdowns, “mydb”, “REL_countries”, “country_code” for foreign database, table and column respectively
  • on table “REL_towns” click Structure, then Relation view
  • in “Choose column to display”, choose “description”
  • repeat the two previous steps for table “REL_countries”

测试步骤如下:

  • Click on your db name in the navigation panel
  • Choose “Query”
  • 使用表: persons、towns、countries
  • Click “Update query”
  • In the columns row, choose persons.person_name and click the “Show” tickbox
  • 为 towns.description 和 countries.descriptions 在另两列中重复上一步
  • Click “Update query” and you will see in the query box that the correct joins have been generated
  • Click “Submit query”

6.7 How can I use the “display column” feature?

Starting from the previous example, create the pma__table_info as explained in the configuration section, then browse your persons table, and move the mouse over a town code or country code. See also 6.21 In edit/insert mode, how can I see a list of possible values for a column, based on some foreign table? for an additional feature that “display column” enables: drop-down list of possible values.

6.8 How can I produce a PDF schema of my database?

First the configuration variables “relation”, “table_coords” and “pdf_pages” have to be filled in. Then you need to think about your schema layout. Which tables will go on which pages?

  • Select your database in the navigation panel.
  • Choose “Operations” in the navigation bar at the top.
  • Choose “Edit PDF Pages” near the bottom of the page.
  • Enter a name for the first PDF page and click Go. If you like, you can use the “automatic layout,” which will put all your linked tables onto the new page.
  • 选择刚才创建的新页 (单选按钮要选中 编辑) 然后点击执行。
  • Select a table from the list, enter its coordinates and click Save. Coordinates are relative; your diagram will be automatically scaled to fit the page. When initially placing tables on the page, just pick any coordinates – say, 50x50. After clicking Save, you can then use the 6.28 How can I easily edit relational schema for export? to position the element correctly.
  • When you’d like to look at your PDF, first be sure to click the Save button beneath the list of tables and coordinates, to save any changes you made there. Then scroll all the way down, select the PDF options you want, and click Go.
  • Internet Explorer for Windows may suggest an incorrect filename when you try to save a generated PDF. When saving a generated PDF, be sure that the filename ends in “.pdf”, for example “schema.pdf”. Browsers on other operating systems, and other browsers on Windows, do not have this problem.

参见

关系

6.9 phpMyAdmin is changing the type of one of my columns!

No, it’s MySQL that is doing silent column type changing.

6.10 When creating a privilege, what happens with underscores in the database name?

If you do not put a backslash before the underscore, this is a wildcard grant, and the underscore means “any character”. So, if the database name is “john_db”, the user would get rights to john1db, john2db … If you put a backslash before the underscore, it means that the database name will have a real underscore.

6.11 What is the curious symbol ø in the statistics pages?

It means “average”.

6.12 I want to understand some Export options.

Structure:

  • “Add DROP TABLE” will add a line telling MySQL to drop the table, if it already exists during the import. It does NOT drop the table after your export, it only affects the import file.
  • “If Not Exists” will only create the table if it doesn’t exist. Otherwise, you may get an error if the table name exists but has a different structure.
  • “Add AUTO_INCREMENT value” ensures that AUTO_INCREMENT value (if any) will be included in backup.
  • “Enclose table and column names with backquotes” ensures that column and table names formed with special characters are protected.
  • “Add into comments” includes column comments, relations, and media types set in the pmadb in the dump as SQL comments (/\ xxx */*).

Data:

  • “Complete inserts” adds the column names on every INSERT command, for better documentation (but resulting file is bigger).
  • “Extended inserts” provides a shorter dump file by using only once the INSERT verb and the table name.
  • “Delayed inserts” are best explained in the MySQL manual - INSERT DELAYED Syntax.
  • “Ignore inserts” treats errors as a warning instead. Again, more info is provided in the MySQL manual - INSERT Syntax, but basically with this selected, invalid values are adjusted and inserted rather than causing the entire statement to fail.

6.13 I would like to create a database with a dot in its name.

This is a bad idea, because in MySQL the syntax “database.table” is the normal way to reference a database and table name. Worse, MySQL will usually let you create a database with a dot, but then you cannot work with it, nor delete it.

6.14 (withdrawn).

6.15 I want to add a BLOB column and put an index on it, but MySQL says “BLOB column ‘…’ used in key specification without a key length”.

The right way to do this, is to create the column without any indexes, then display the table structure and use the “Create an index” dialog. On this page, you will be able to choose your BLOB column, and set a size to the index, which is the condition to create an index on a BLOB column.

6.16 How can I simply move in page with plenty editing fields?

You can use Ctrl+arrows (Option+Arrows in Safari) for moving on most pages with many editing fields (table structure changes, row editing, etc.).

6.17 Transformations: I can’t enter my own mimetype! What is this feature then useful for?

Defining mimetypes is of no use if you can’t put transformations on them. Otherwise you could just put a comment on the column. Because entering your own mimetype will cause serious syntax checking issues and validation, this introduces a high-risk false- user-input situation. Instead you have to initialize mimetypes using functions or empty mimetype definitions.

Plus, you have a whole overview of available mimetypes. Who knows all those mimetypes by heart so they can enter it at will?

6.18 Bookmarks: Where can I store bookmarks? Why can’t I see any bookmarks below the query box? What are these variables for?

You need to have configured the phpMyAdmin 高级功能 for using bookmarks feature. Once you have done that, you can use bookmarks in the SQL tab.

参见

书签

6.19 How can I create simple LATEX document to include exported table?

You can simply include table in your LATEX documents, minimal sample document should look like following one (assuming you have table exported in file table.tex):

  1. \documentclass{article} % or any class you want
  2. \usepackage{longtable} % for displaying table
  3. \begin{document} % start of document
  4. \include{table} % including exported table
  5. \end{document} % end of document

6.20 I see a lot of databases which are not mine, and cannot access them.

You have one of these global privileges: CREATE TEMPORARY TABLES, SHOW DATABASES, LOCK TABLES. Those privileges also enable users to see all the database names. So if your users do not need those privileges, you can remove them and their databases list will shorten.

参见

[https://bugs.mysql.com/bug.php?id=179](https://bugs.mysql.com/bug.php?id=179)\

6.21 In edit/insert mode, how can I see a list of possible values for a column, based on some foreign table?

你需要正确设置两张表之间的关系,同时还要在外键表设置 “显示字段” 。参见 6.6 How can I use the relation table in Query-by-example? 中的例子。这时,如果外键表中有不超过 100 个值,就会出现一个下拉框。 你将会看到两个列表,第一个列表包含键和显示字段,第二个列表包含显示字段和键。这么做的目的是为了可以通过按下键或显示字段的首字母来定位。对于100个或更多值,将显示一个不同的窗口,以浏览外键值并选择一个。要更改默认限制100,请参阅 $cfg['ForeignKeyMaxLimit']

6.22 Bookmarks: Can I execute a default bookmark automatically when entering Browse mode for a table?

Yes. If a bookmark has the same label as a table name and it’s not a public bookmark, it will be executed.

参见

书签

6.23 Export: I heard phpMyAdmin can export Microsoft Excel files?

You can use CSV for Microsoft Excel, which works out of the box.

在 3.4.5 版更改: Since phpMyAdmin 3.4.5 support for direct export to Microsoft Excel version 97 and newer was dropped.

6.24 Now that phpMyAdmin supports native MySQL 4.1.x column comments, what happens to my column comments stored in pmadb?

它们将在你进入该表的结构页面时自动并入。

6.25 (withdrawn).

6.26 How can I select a range of rows?

先点击要选择的第一行,按住 Shift 键不放并点击最后一行。这在任何有行的地方都有效,例如浏览模式和结构页面。

6.27 What format strings can I use?

In all places where phpMyAdmin accepts format strings, you can use @VARIABLE@ expansion and strftime format strings. The expanded variables depend on a context (for example, if you haven’t chosen a table, you can not get the table name), but the following variables can be used:

@HTTP_HOST@

运行 phpMyAdmin 的 HTTP 主机

@SERVER@

MySQL 服务器名

@VERBOSE@

Verbose MySQL server name as defined in $cfg['Servers'][$i]['verbose']

@VSERVER@

如果设置了详细的 MySQL 服务器名则使用,否则使用常规的服务器名

@DATABASE@

当前打开的数据库

@TABLE@

当前打开的数据表

@COLUMNS@

Columns of the currently opened table

@PHPMYADMIN@

带版本号的 phpMyAdmin 字样

6.28 How can I easily edit relational schema for export?

By clicking on the button ‘toggle scratchboard’ on the page where you edit x/y coordinates of those elements you can activate a scratchboard where all your elements are placed. By clicking on an element, you can move them around in the pre-defined area and the x/y coordinates will get updated dynamically. Likewise, when entering a new position directly into the input field, the new position in the scratchboard changes after your cursor leaves the input field.

You have to click on the ‘OK’-button below the tables to save the new positions. If you want to place a new element, first add it to the table of elements and then you can drag the new element around.

By changing the paper size and the orientation you can change the size of the scratchboard as well. You can do so by just changing the dropdown field below, and the scratchboard will resize automatically, without interfering with the current placement of the elements.

If ever an element gets out of range you can either enlarge the paper size or click on the ‘reset’ button to place all elements below each other.

6.29 Why can’t I get a chart from my query result table?

不是所有的表都能显示为图表。只有包含一个、两个或者三个字段的表才能通过图表表现出来。并且它还必须具有能令图表脚本理解的特定格式。当前所支持的格式可以在 图表 中找到。

6.30 Import: How can I import ESRI Shapefiles?

An ESRI Shapefile is actually a set of several files, where .shp file contains geometry data and .dbf file contains data related to those geometry data. To read data from .dbf file you need to have PHP compiled with the dBase extension (–enable-dbase). Otherwise only geometry data will be imported.

To upload these set of files you can use either of the following methods:

Configure upload directory with $cfg['UploadDir'], upload both .shp and .dbf files with the same filename and chose the .shp file from the import page.

Create a zip archive with .shp and .dbf files and import it. For this to work, you need to set $cfg['TempDir'] to a place where the web server user can write (for example './tmp').

要在 UNIX 类系统下创建一个临时目录,可以通过:

  1. cd phpMyAdmin
  2. mkdir tmp
  3. chmod o+rwx tmp

6.31 How do I create a relation in designer?

To select relation, click: The display column is shown in pink. To set/unset a column as the display column, click the “Choose column to display” icon, then click on the appropriate column name.

6.32 How can I use the zoom search feature?

The Zoom search feature is an alternative to table search feature. It allows you to explore a table by representing its data in a scatter plot. You can locate this feature by selecting a table and clicking the Search tab. One of the sub-tabs in the Table Search page is Zoom Search.

Consider the table REL_persons in 6.6 How can I use the relation table in Query-by-example? for an example. To use zoom search, two columns need to be selected, for example, id and town_code. The id values will be represented on one axis and town_code values on the other axis. Each row will be represented as a point in a scatter plot based on its id and town_code. You can include two additional search criteria apart from the two fields to display.

You can choose which field should be displayed as label for each point. If a display column has been set for the table (see 6.7 How can I use the “display column” feature?), it is taken as the label unless you specify otherwise. You can also select the maximum number of rows you want to be displayed in the plot by specifing it in the ‘Max rows to plot’ field. Once you have decided over your criteria, click ‘Go’ to display the plot.

After the plot is generated, you can use the mousewheel to zoom in and out of the plot. In addition, panning feature is enabled to navigate through the plot. You can zoom-in to a certain level of detail and use panning to locate your area of interest. Clicking on a point opens a dialogue box, displaying field values of the data row represented by the point. You can edit the values if required and click on submit to issue an update query. Basic instructions on how to use can be viewed by clicking the ‘How to use?’ link located just above the plot.

6.33 When browsing a table, how can I copy a column name?

Selecting the name of the column within the browse table header cell for copying is difficult, as the columns support reordering by dragging the header cells as well as sorting by clicking on the linked column name. To copy a column name, double-click on the empty area next to the column name, when the tooltip tells you to do so. This will show you an input box with the column name. You may right-click the column name within this input box to copy it to your clipboard.

6.34 How can I use the Favorite Tables feature?

Favorite Tables feature is very much similar to Recent Tables feature. It allows you to add a shortcut for the frequently used tables of any database in the navigation panel . You can easily navigate to any table in the list by simply choosing it from the list. These tables are stored in your browser’s local storage if you have not configured your phpMyAdmin Configuration Storage. Otherwise these entries are stored in phpMyAdmin Configuration Storage.

IMPORTANT: In absence of phpMyAdmin Configuration Storage, your Favorite tables may be different in different browsers based on your different selections in them.

To add a table to Favorite list simply click on the Gray star in front of a table name in the list of tables of a Database and wait until it turns to Yellow. To remove a table from list, simply click on the Yellow star and wait until it turns Gray again.

Using $cfg['NumFavoriteTables'] in your config.inc.php file, you can define the maximum number of favorite tables shown in the navigation panel. Its default value is 10.

6.35 How can I use the Range search feature?

With the help of range search feature, one can specify a range of values for particular column(s) while performing search operation on a table from the Search tab.

To use this feature simply click on the BETWEEN or NOT BETWEEN operators from the operator select list in front of the column name. On choosing one of the above options, a dialog box will show up asking for the Minimum and Maximum value for that column. Only the specified range of values will be included in case of BETWEEN and excluded in case of NOT BETWEEN from the final results.

Note: The Range search feature will work only Numeric and Date data type columns.

6.36 What is Central columns and how can I use this feature?

As the name suggests, the Central columns feature enables to maintain a central list of columns per database to avoid similar name for the same data element and bring consistency of data type for the same data element. You can use the central list of columns to add an element to any table structure in that database which will save from writing similar column name and column definition.

To add a column to central list, go to table structure page, check the columns you want to include and then simply click on “Add to central columns”. If you want to add all unique columns from more than one table from a database then go to database structure page, check the tables you want to include and then select “Add columns to central list”.

To remove a column from central list, go to Table structure page, check the columns you want to remove and then simply click on “Remove from central columns”. If you want to remove all columns from more than one tables from a database then go to database structure page, check the tables you want to include and then select “Remove columns from central list”.

To view and manage the central list, select the database you want to manage central columns for then from the top menu click on “Central columns”. You will be taken to a page where you will have options to edit, delete or add new columns to central list.

6.37 How can I use Improve Table structure feature?

Improve table structure feature helps to bring the table structure upto Third Normal Form. A wizard is presented to user which asks questions about the elements during the various steps for normalization and a new structure is proposed accordingly to bring the table into the First/Second/Third Normal form. On startup of the wizard, user gets to select upto what normal form they want to normalize the table structure.

Here is an example table which you can use to test all of the three First, Second and Third Normal Form.

  1. CREATE TABLE `VetOffice` (
  2. `petName` varchar(64) NOT NULL,
  3. `petBreed` varchar(64) NOT NULL,
  4. `petType` varchar(64) NOT NULL,
  5. `petDOB` date NOT NULL,
  6. `ownerLastName` varchar(64) NOT NULL,
  7. `ownerFirstName` varchar(64) NOT NULL,
  8. `ownerPhone1` int(12) NOT NULL,
  9. `ownerPhone2` int(12) NOT NULL,
  10. `ownerEmail` varchar(64) NOT NULL,
  11. );

The above table is not in First normal Form as no primary key exists. Primary key is supposed to be (petName,`ownerLastName`,`ownerFirstName`) . If the primary key is chosen as suggested the resultant table won’t be in Second as well as Third Normal form as the following dependencies exists.

  1. (OwnerLastName, OwnerFirstName) -> OwnerEmail
  2. (OwnerLastName, OwnerFirstName) -> OwnerPhone
  3. PetBreed -> PetType

Which says, OwnerEmail depends on OwnerLastName and OwnerFirstName. OwnerPhone depends on OwnerLastName and OwnerFirstName. PetType depends on PetBreed.

6.38 How can I reassign auto-incremented values?

Some users prefer their AUTO_INCREMENT values to be consecutive; this is not always the case after row deletion.

Here are the steps to accomplish this. These are manual steps because they involve a manual verification at one point.

  • Ensure that you have exclusive access to the table to rearrange
  • On your primary key column (i.e. id), remove the AUTO_INCREMENT setting
  • Delete your primary key in Structure > indexes
  • Create a new column future_id as primary key, AUTO_INCREMENT
  • Browse your table and verify that the new increments correspond to what you’re expecting
  • Drop your old id column
  • Rename the future_id column to id
  • Move the new id column via Structure > Move columns

6.39 What is the “Adjust privileges” option when renaming, copying, or moving a database, table, column, or procedure?

When renaming/copying/moving a database/table/column/procedure, MySQL does not adjust the original privileges relating to these objects on its own. By selecting this option, phpMyAdmin will adjust the privilege table so that users have the same privileges on the new items.

For example: A user ‘bob’@’localhost’ has a ‘SELECT’ privilege on a column named ‘id’. Now, if this column is renamed to ‘id_new’, MySQL, on its own, would not adjust the column privileges to the new column name. phpMyAdmin can make this adjustment for you automatically.

Notes:

  • While adjusting privileges for a database, the privileges of all database-related elements (tables, columns and procedures) are also adjusted to the database’s new name.
  • Similarly, while adjusting privileges for a table, the privileges of all the columns inside the new table are also adjusted.
  • While adjusting privileges, the user performing the operation must have the following privileges:
    • SELECT, INSERT, UPDATE, DELETE privileges on following tables: mysql.`db`, mysql.`columns_priv`, mysql.`tables_priv`, mysql.`procs_priv`
    • FLUSH privilege (GLOBAL)

Thus, if you want to replicate the database/table/column/procedure as it is while renaming/copying/moving these objects, make sure you have checked this option.

6.40 I see “Bind parameters” checkbox in the “SQL” page. How do I write parameterized SQL queries?

From version 4.5, phpMyAdmin allows users to execute parameterized queries in the “SQL” page. Parameters should be prefixed with a colon(:) and when the “Bind parameters” checkbox is checked these parameters will be identified and input fields for these parameters will be presented. Values entered in these field will be substituted in the query before being executed.

6.41 I get import errors while importing the dumps exported from older MySQL versions (pre-5.7.6) into newer MySQL versions (5.7.7+), but they work fine when imported back on same older versions ?

If you get errors like #1031 - Table storage engine for ‘table_name’ doesn’t have this option while importing the dumps exported from pre-5.7.7 MySQL servers into new MySQL server versions 5.7.7+, it might be because ROW_FORMAT=FIXED is not supported with InnoDB tables. Moreover, the value of innodb_strict_mode would define if this would be reported as a warning or as an error.

Since MySQL version 5.7.9, the default value for innodb_strict_mode is ON and thus would generate an error when such a CREATE TABLE or ALTER TABLE statement is encountered.

There are two ways of preventing such errors while importing:

  • Change the value of innodb_strict_mode to OFF before starting the import and turn it ON after the import is successfully completed.
  • This can be achieved in two ways:
    • Go to ‘Variables’ page and edit the value of innodb_strict_mode
    • Run the query : SET GLOBAL `innodb_strict_mode = ‘[value]’`

After the import is done, it is suggested that the value of innodb_strict_mode should be reset to the original value.