Basic help on using HeidiSQL关于使用HeidiSQL的基本帮助

This document aims to give users some basic help to get started with HeidiSQL. 本文档旨在为用户提供一些基本帮助,帮助他们开始使用HeidiSQL。Over the years, the feature list has grown longer and longer. 多年来,功能列表越来越长。So, especially new users sometimes don't know where to look at for particular things. 因此,特别是新用户有时不知道在哪里可以找到特定的东西。In such cases, you can watch out here for a first help. 在这种情况下,你可以注意这里的第一帮助。If you don't find what you're looking for, please register in the forum and post a question.如果你找不到你想要的,请在论坛中注册并发布一个问题。

Requirements要求

HeidiSQL runs fine on Windows 8 and 10 (and on Windows 7 with some minor issues). HeidiSQL在Windows 8和10上运行良好(在Windows 7上也有一些小问题)。Running HeidiSQL on Wine is currently quite unstable.在Wine上运行HeidiSQL目前相当不稳定。

Connecting to a server连接到服务器

Basics基础

HeidiSQL is a so called client application, only usable when you have some server available. HeidiSQL是一个所谓的客户端应用程序,只有当您有一些服务器可用时才可用。So, make sure you have some MariaDB, MySQL, MS SQL, PostgreSQL server or SQLite database file to connect to.因此,请确保您有一些MariaDB、MySQL、MS SQL、PostgreSQL server或SQLite数据库文件要连接。

connection

A simple setup is to have a MariaDB server installed on localhost (equivalent to the special IP address 127.0.0.1). 一个简单的设置是在本地主机上安装一个MariaDB服务器(相当于特殊IP地址127.0.0.1)。In HeidiSQL's session manager, you click on the "New" button to create a new connection, and most default settings are already set for you, except from the password, which is mostly not an empty one on a newly installed MariaDB server:在HeidiSQL的会话管理器中,您单击“新建”按钮创建新连接,大多数默认设置都已为您设置,但密码除外,在新安装的MariaDB服务器上,密码大多不是空的:

You can organize your stored sessions in folders. 您可以在文件夹中组织存储的会话。To create a folder, click the dropdown arrow on the "New" button, then click "Folder in root folder" or "Folder in selected folder". 要创建文件夹,请单击“新建”按钮上的下拉箭头,然后单击“根文件夹中的文件夹”或“选定文件夹中的文件夹”。Once you have a folder, you can create connections in it, or drag existing connections into that folder.拥有文件夹后,可以在其中创建连接,或将现有连接拖动到该文件夹中。

Setting up a SSH tunnel connection to MariaDB/MySQL/PostgreSQL设置到MariaDB/MySQL/PostgreSQL的SSH隧道连接

If your MariaDB/MySQL/PostgreSQL server is located on a remote machine which is only accessible via SSH, then you still can use HeidiSQL to connect to it. 如果您的MariaDB/MySQL/PostgreSQL服务器位于只能通过SSH访问的远程计算机上,那么您仍然可以使用HeidiSQL连接到它。You just need the additional plink.exe from the PuTTY project, place it somewhere on your harddisk, and finally tell HeidiSQL where it is and the SSH credentials plus the MariaDB/MySQL/PostgreSQL credentials.您只需从PuTTY项目中获得额外的plink.exe,将其放在硬盘上的某个位置,最后告诉HeidiSQL它在哪里,以及SSH凭据和MariaDB/MySQL/PostgreSQL凭据。

Note that the default host name for the SSH server is the one you entered in the "Settings" tab. 请注意,SSH服务器的默认主机名是您在“设置”选项卡中输入的主机名。HeidiSQL then advices plink.exe to connect to that host name, or, when you entered a SSH host name, that one is taken. 然后,HeidiSQL建议plink.exe连接到该主机名,或者,当您输入SSH主机名时,将使用该主机名。Additionally, the host name on the "Settings" tab is always taken for the -L (listen) option in plink.exe.此外,“设置”选项卡上的主机名始终用于plink.exe中的-L(侦听)选项。

ssh tunnel

Example settings:示例设置:

The following error, or a similar one, is mostly caused by a tunnel onto the official IP address of your remote server:以下错误或类似错误主要由远程服务器的官方IP地址上的隧道引起:

Lost connection to MySQL server at 'reading initial communication packet', system error: 0 "Internal error/check (Not system error)"“读取初始通信数据包”时与MySQL服务器的连接中断,系统错误:0“内部错误/检查(非系统错误)”
In such cases, ensure you're using "127.0.0.1" in Settings > Hostname/IP, and the remote IP of your server in SSH tunnel > Host.在这种情况下,请确保在“设置”>“主机名/IP”中使用“127.0.0.1”,并在“SSH隧道”>“主机”中使用服务器的远程IP。

Command line switches命令行开关

Although HeidiSQL is a pure GUI application, it can be automated for connecting and opening files via command line parameters. 尽管HeidiSQL是一个纯GUI应用程序,但它可以通过命令行参数自动连接和打开文件。Parameter names are case sensitive and are based on those used by the MariaDB/MySQL command line applications, e.g. mysqldump.参数名称区分大小写,并基于MariaDB/MySQL命令行应用程序使用的名称,例如mysqldump。

Common pitfalls:常见陷阱:

Short switch短开关 Long switch长开关 Description描述 Default value默认值
-d --description Session name会话名称
-n --nettype Network protocol type:网络协议类型:
  • 0 = MariaDB/MySQL (TCP/IP)
  • 1 = MariaDB/MySQL (named pipe)
  • 2 = MariaDB/MySQL (SSH tunnel)
  • 3 = MSSQL (named pipe)
  • 4 = MSSQL (TCP/IP)
  • 5 = MSSQL (SPX/IPX)
  • 6 = MSSQL (Banyan VINES)
  • 7 = MSSQL (Windows RPC)
  • 8 = PostgreSQL (TCP/IP)
  • 9 = PostgreSQL (SSH tunnel)
  • 10 = SQLite
  • 11 = ProxySQL Admin
0
-h --host Host name主机名
-l --library Library or provider (added in v11.1):库或提供程序(在v11.1中添加):
  • MySQL/MariaDB:
    • libmariadb.dll
    • libmysql.dll
    • libmysql-6.1.dll
    • ... any fitting dll from your HeidiSQL directory
  • MS SQL:
    • MSOLEDBSQL
    • SQLOLEDB
  • PostgreSQL:
    • libpq.dll
    • libpq-12.dll
    • ... any fitting dll from your HeidiSQL directory
  • SQLite:
    • sqlite3.dll
    • ... any fitting dll from your HeidiSQL directory
Depends on the given network protocol, see underlined values取决于给定的网络协议,请参阅带下划线的值
-u --user User name用户名
-p --password Password密码
-P --port Port端口 3306
-S --socket Socket name, for connecting via named pipe套接字名称,用于通过命名管道连接
-db --databases Databases, separated by semicolon. 数据库,以分号分隔。Single database on PostgreSQL.PostgreSQL上的单个数据库。
-W --winauth Use Windows authentication: 1 or 0. 使用Windows身份验证:1或0。(MSSQL only, added in v9.4).(仅MSSQL,在v9.4中添加)。 0
-cte --cleartextenabled Enable cleartext authentication: 1 or 0. 启用明文身份验证:1或0。(MySQL and MariaDB only) 0
  --ssl Use SSL. (1=yes, 0=no) 0
-sslpk --sslprivatekey SSL private keySSL私钥  
-sslca --sslcacertificate SSL CA certificateSSL CA证书  
-sslcert --sslcertificate SSL certificateSSL证书  
-sslcip --sslcipher SSL cipher  
  --psettings Custom filename for portable settings. 可移植设置的自定义文件名。Ignored if file does not exist.如果文件不存在,则忽略。 portable_settings.txt (if that file exists)portable_settings.txt(如果该文件存在)

Examples:示例:

The database tree数据库树

When you have a large amount of tables, views or whatever in your database(s), you probably want to group these by their type, for a better overview. 当您的数据库中有大量的表、视图或其他内容时,您可能希望根据它们的类型对它们进行分组,以获得更好的概览。Just right click the tree and activate Tree style options > Group objects by type:只需右键单击树并激活“树样式选项”>“按类型对对象分组”:

Tree folders

You can also mark important items as so called favorites, by mouse click on the very left area of a table. 您还可以通过鼠标单击表格最左侧区域,将重要项目标记为“收藏夹”。Afterwards, you can limit the tree to show only favorites by a click on the new "Show only favorites" button at the top:之后,您可以通过单击顶部的新“仅显示收藏夹”按钮,将树限制为仅显示收藏夹:

Favorites

Creating a table创建表

HeidiSQL comes with a feature-rich GUI for creating and editing a table structure. HeidiSQL提供了一个功能丰富的GUI,用于创建和编辑表结构。Just right click the datatabase in which you want to create a table, then point on "Create new", then click "Table":只需右键单击要在其中创建表的数据库,然后指向“新建”,然后单击“表”:

Create table

Done that, you'll see the table editor like in the following picture:完成此操作后,您将看到如下图所示的表格编辑器:

Table editor

Creating a view创建视图

Click "Create new", then click "View", to show up the view editor. 单击“新建”,然后单击“视图”,以显示视图编辑器。Creating a view is basically like writing a SELECT query. 创建视图基本上类似于编写SELECT查询。Give it a name, and click the save button to create it. 为它命名,然后单击“保存”按钮创建它。HeidiSQL shows the data of the view in the "Data" tab, like for tables.HeidiSQL在“数据”选项卡中显示视图的数据,与表类似。

One thing you might notice is that MySQL and MariaDB are reformatting the SELECT query in the view when you save it. 您可能会注意到,当您保存SELECT查询时,MySQL和MariaDB正在视图中重新格式化该查询。This destroys indentation, and converts the whole query into a one-liner. 这会破坏缩进,并将整个查询转换为一行。HeidiSQL tries its best to restore the original code of the view, by loading it from the *.frm file on the server. HeidiSQL通过从服务器上的*.frm文件加载来尽最大努力恢复视图的原始代码。However, this fails in many cases, often due to restricted file privileges. 但是,在许多情况下,这会失败,通常是由于受限制的文件权限。For such cases, the only way to make it readable again is to use HeidiSQL's reformatter (Ctrl+F8).对于这种情况,使其再次可读的唯一方法是使用HeidiSQL的重新格式化(Ctrl+F8)。

View editor

Creating a stored procedure创建存储过程

Just right click the datatabase in which you want to create a procedure, then point on "Create new", then click "Procedure" or "Function". 只需右键单击要在其中创建过程的数据库,然后指向“新建”,然后单击“过程”或“函数”。Done that, you'll see the procedure editor like in the following picture:完成此操作后,您将看到如下图所示的过程编辑器:

Procedure editor

Creating a trigger创建触发器

Trigger editor

Creating a scheduled event创建计划的事件

Event editor

The Data tab“数据”选项卡

On the data tab, the contents of the currently selected table or view are displayed. 在“数据”选项卡上,将显示当前选定表或视图的内容。This is one of the most useful and powerful features of HeidiSQL. 这是HeidiSQL最有用、最强大的特性之一。You will see different colors for the various groups of data types. 您将看到不同数据类型组的不同颜色。These colors are customizable in Tools > Preferences > Data appearance.这些颜色可在“工具”>“偏好”>“数据外观”中自定义。

Pressing F2 or one-long-click in a grid cell will start the editor mode. F2键或在网格单元中长按一次将启动编辑器模式。This will allow you inserting ordinary values into a row. 这将允许您将普通值插入行中。For inserting special values, such as SQL functions, NULL or GUIDs, right click a cell, and point to the Insert value > submenu.要插入特殊值,如SQL函数、NULL或GUID,请右键单击单元格,并指向“插入值”>子菜单。

Quick filters快速筛选: Right click a value in the grid, then click Quick filter to get various one-click options to create a WHERE clause on the grid values. :在网格中的值上单击鼠标右键,然后单击“快速筛选”以获得各种单击选项,从而在网格值上创建WHERE子句。This filter can be base on either the focused cell in the grid, a prompted value, or on the contents of your clipboard.此筛选器可以基于网格中的聚焦单元格、提示值或剪贴板的内容。

In the Quick filter sub menu, you will find a More values sub-sub-menu. 在“快速筛选”子菜单中,您将找到“更多值”子菜单。Pointing to that menu, HeidiSQL quickly collects and displays the top 30 items in the focused column, grouped by their value:指向该菜单,HeidiSQL快速收集并显示聚焦列中的前30项,并按其值分组:

More values

Finding specific values in such a grid can be a pain. 在这样的网格中寻找特定的值可能是一件痛苦的事情。For a simple client side filter, you can enter some value in the filter panel. 对于简单的客户端筛选器,可以在筛选器面板中输入一些值。Activate it in Edit > Filter panel (Ctrl+Alt+F):在“编辑”>“筛选器器面板”(Ctrl+Alt+F)中激活它:

Filter panel

HeidiSQL can also assists you with a Search and replace dialog (Find mode: Ctrl+F, Replace mode: Ctrl+R). HeidiSQL还可以用“搜索和替换”对话框帮助你(查找模式:Ctrl+F,替换模式:Ctrl+R)。That dialog can be used on SQL query tabs too.该对话框也可用于SQL查询选项卡。

Search and replace

Binary values, also called BLOBs, are by default displayed in hexadecimal format, which is mostly unreadable for a human being. 二进制值,也称为BLOB,默认情况下以十六进制格式显示,这对于人类来说是不可读的。For cases in which such BLOBs contain readable text, HeidiSQL offers to toggle between hex-mode and text-mode. 对于此类blob包含可读文本的情况,HeidiSQL提供在十六进制模式和文本模式之间切换。Press or "unpress" the white button with the purple "0x" on it:按下或“取消按下”带有紫色“0x”的白色按钮:

hex

Probably you have a table with one or more integer columns which represent UNIX timestamps. 您可能有一个表,其中包含一个或多个表示UNIX时间戳的整数列。HeidiSQL can display such integer columns as date/time values, so you can better read them:HeidiSQL可以显示日期/时间值等整数列,因此您可以更好地读取它们:

UNIX timestamps

Running SQL queries运行SQL查询

HeidiSQL has a "Query" tab by default. 默认情况下,HeidiSQL有一个“查询”选项卡。You can create more than this default one by pressing Ctrl+T, or by right clicking the main tabs, then click "New query tab". 通过按Ctrl+T,或者右键单击主要选项卡,然后单击“新建查询选项卡”,可以创建多个默认选项卡。In such a query tab, you can write your own database queries, or load a .sql file from your harddisk. 在这样的查询选项卡中,您可以编写自己的数据库查询,或从硬盘加载.sql文件。Pressing F9, or the button with the blue "play" icon on it executes your query or queries.F9键或带有蓝色“播放”图标的按钮可执行一个或多个查询。

Compound queries e.g. for creating a function often have a semicolon inside the query. 复合查询(例如用于创建函数的查询)通常在查询内有分号。As HeidiSQL separates queries at each semicolon, you will get syntax errors when you run such commands. 由于HeidiSQL在每个分号处分隔查询,因此在运行此类命令时会出现语法错误。You can set a different query delimiter for such purposes, e.g. "!!", as shown in the screenshot:您可以为此目的设置不同的查询分隔符,例如“!!”,如屏幕截图所示:

Query delimiter

Alternatively, you can change the delimiter via code:或者,您可以通过以下代码更改分隔符:

DELIMITER !!
-- your code
DELIMITER ;

On the right hand of each query tab, you have the "query helpers" panel, with table columns, reserved words, SQL functions etc. 在每个查询选项卡的右侧,都有“查询帮助程序”面板,其中包含表列、保留字、SQL函数等。
Having a table selected in the left tree, the first tree item in the helpers show "Columns in <selected-table>". 在左树中选择一个表后,助手中的第一个树项将显示“<所选表格>中的列”。The contained "Generate..." menu items use the selected column names to create a quick query for you in the editor:包含的“生成…”菜单项使用选定的列名在编辑器中为您创建快速查询:

Quickly generate basic queries

To see how your query performs in MariaDB or MySQL, you can activate the "Query profile" option in the helpers box on the right. 要查看您的查询在MariaDB或MySQL中的执行情况,可以激活右侧帮助框中的“查询配置文件”选项。Then, run your query or queries, and see what the profile timings show. 然后,运行一个或多个查询,查看配置文件计时显示的内容。This is basically what SHOW PROFILE in MySQL 5.0.37 and later releases does.这基本上就是MySQL 5.0.37及更高版本中的Show Profile所做的。

Query profile

HeidiSQL supports parameterized SQL queries: Activate it per click on the checkbox "Bind parameter", and start writing a query with parameters, e.g. select ':p'.HeidiSQL支持参数化SQL查询:单击复选框“绑定参数”激活它,然后开始编写带有参数的查询,例如select ':p'

Query parameters

The first part of the bind parameter implementation was done by Adrian Granger.绑定参数实现的第一部分由Adrian Granger完成。

HeidiSQL can execute a batch of queries (= multiple queries, separated by semicolon) in one go. HeidiSQL可以一次性执行一批查询(=多个查询,用分号分隔)。That way, execution gets dramatically faster, especially when having tons of mini queries. 这样,执行速度会显著加快,特别是当有大量的迷你查询时。To activate that "one go execution", just click the drop down menu of the blue "play" button, then click "Send batch in one go":要激活“一次性执行”,只需单击蓝色“播放”按钮的下拉菜单,然后单击“一次性发送批次”:

Batch execution

SQL export导出

HeidiSQL can generate nice SQL export files for you. HeidiSQL可以为您生成漂亮的SQL导出文件。This is basically what mysqldump also does. 这就是mysqldump的基本功能。However, you can also tell HeidiSQL to put the results of the export into但是,您也可以告诉HeidiSQL将导出结果放入

SQL export
Database(s)数据库
Controls whether to a) drop an existing database on the target server first, and b) create it.控制是否(a)首先删除目标服务器上的现有数据库,以及(b)创建它。
This is meant for the target server, not the source server!这是针对目标服务器,而不是源服务器!
Table(s)
Same as above, just for tables, views, procedures etc. 同上,仅适用于表、视图、过程等。When checked, the table(s) will be dropped first, and/or created afterwards.选中时,将首先删除表,然后创建表。
Data数据
How the rows are created on the target server. 如何在目标服务器上创建行。Select "No data" to make a structure-only export. 选择“无数据”以只导出结构。Default is "INSERT".默认值为“插入”。
Max INSERT size最大插入大小
Defines the maximum size of the extended INSERT statements, which can hold multiple rows in one statement. 定义扩展INSERT语句的最大大小,该语句可以在一条语句中容纳多行。Note that a MariaDB/MySQL server limits the size of a query sent to the server by the server variable max_allowed_packet. 请注意,MariaDB/MySQL服务器通过服务器变量max_allowed_packet限制了发送到服务器的查询的大小。Be sure to use a lower value in this dialog, otherwise MariaDB/MySQL will kill your connection when importing that file.请确保在此对话框中使用较低的值,否则在导入该文件时,MariaDB/MySQL将终止您的连接。
Output输出
Either select a filename (zip compressed or uncompressed), a directory in which HeidiSQL will place .sql files, clipboard, another database or a configured HeidiSQL (and a database name below).选择一个文件名(zip压缩或未压缩),HeidiSQL将放置.sql文件、剪贴板、另一个数据库或配置的HeidiSQL(和下面的数据库名称)的目录。
Filename, Directory, or Database文件名、目录或数据库
Depends on what you selected in the "output" pulldown menu.取决于您在“输出”下拉菜单中选择的内容。

Importing files导入文件

HeidiSQL can import .sql files with data rows and/or structure, .csv files with data rows and binary files for BLOBs.HeidiSQL可以导入带有数据行和/或结构的.sql文件,以及带有数据行的.csv文件和用于blob的二进制文件。

Importing .sql files导入.sql文件

At first, activate the database you want the import to run in. 首先,激活要在其中运行导入的数据库。Then, go to File > "Run SQL file", and select the file to import. 然后,转到“文件”>“运行SQL文件”,然后选择要导入的文件。Below the filename input box, you will find an Encoding dropdown menu. 在文件名输入框下方,您将看到一个编码下拉菜单。Using "Auto detect" is a common way to get broken data afterwards使用“自动检测”是事后获取损坏数据的常用方法 - so if are sure about the encoding in that file, you should definitely select the right one, e.g. "UTF-8". 因此,如果您确定该文件中的编码,您应该选择正确的编码,例如“UTF-8”。After clicking "OK", HeidiSQL will start to execute the contained commands immediately, and you can watch the progress:单击“确定”后,HeidiSQL将立即开始执行包含的命令,您可以观察进度:

SQL import

Importing .csv files (text files)导入.csv文件(文本文件)

A .csv file is a text file with data rows for one table. .csv文件是一个文本文件,其中包含一个表的数据行。You can import such a file into a table via Tools > "Import CSV file". 您可以通过“工具”>“导入CSV文件”将此类文件导入表。You will have to tell HeidiSQL the format of the file (line terminator, enclosing character etc.).您必须告诉HeidiSQL文件的格式(行终止符、封闭字符等)。

CSV import

Importing binary or text files into BLOBs将二进制或文本文件导入Blob

Via Tools > "Insert files into TEXT/BLOB fields", you can insert new rows from all kind of files into your tables. 通过“工具”>“将文件插入文本/BLOB字段”,您可以将各种文件中的新行插入表中。First, select the database and the table you want to put the files into. 首先,选择要将文件放入的数据库和表。Then, click on the green "Add" button, to add one or more files to the listing. 然后,单击绿色的“添加”按钮,将一个或多个文件添加到列表中。In the upper listing you will have to tell HeidiSQL with placeholders in which column the file content goes. 在上面的清单中,您必须用占位符告诉HeidiSQL文件内容位于哪个列。In the "Value" column, click besides the right field name and select '%filecontent%'. 在“值”列中,单击右侧字段名旁边的,然后选择'%filecontent%'Some other placeholders are available in that dropdown. 其他一些占位符在该下拉列表中可用。You can also wrap the placeholders (or even static text) with some SQL function. 您还可以使用一些SQL函数包装占位符(甚至静态文本)。For example if you want the file name in lowercase, you apply LOWER('%filename%').例如,如果希望文件名为小写,则应用LOWER('%filename%')

Import files

HeidiSQL portableHeidiSQL便携式

If HeidiSQL finds a portable.lock file, or a portable_settings.txt, or the custom filename as noted above, it starts in portable mode. Which means basically that all settings are restored from that file and when exiting stored again into that file.如果HeidiSQL找到一个portable.lock文件,或portable_settings.txt,或如上所述的自定义文件名,它将以便携模式启动。这基本上意味着所有设置都从该文件中恢复,并且在退出时再次存储到该文件中。

When you download the portable package, that portable_settings.txt needs to be manually copied from your old portable HeidiSQL directory. 下载便携包时,需要手动从旧的便携HeidiSQL目录复制portable_settings.txtNot doing so will show you an empty session manager.不这样做将显示一个空的会话管理器。

License许可证

HeidiSQL is OpenSource and released under GPL (GNU GENERAL PUBLIC LICENSE). HeidiSQL是开源的,在GPL(GNU通用公共许可证)下发布。See the license.txt for more details.有关更多详细信息,请参阅license.txt

Probably HeidiSQL saved you a lot of time and you like it. 也许HeidiSQL为您节省了很多时间,您也喜欢它。In this case you may make a donation here.在这种情况下,你可以在这里捐款

Credits信用

Third party components and graphics:第三方组件和图形:

Former development contributors:以往的开发捐助者:

Thanks to Transifex.com for a free translation account, and all the registered translators.感谢Transifex.com提供的免费翻译帐户,以及所有注册的翻译人员。

1000 thanks for great database software:1000次感谢您提供出色的数据库软件: