Navicat for SQL使用注意(设置默认字符集,外键保存不了)
最近用mysqlNavicat for sql开发项目时遇到了以下问题: 1.默认创建的数据库,字符集编码为:latin1 -- cp1252 West European 在数据库中存储中文时会出现乱码错误 2.用Navicat给数据库添加外键约束时,保存不了,保存后消失 解决方案: 1对于字符集问题有3
最近用mysql+Navicat for sql开发项目时遇到了以下问题:
1.默认创建的数据库,字符集编码为:latin1 -- cp1252 West European
在数据库中存储中文时会出现乱码错误
2.用Navicat给数据库添加外键约束时,保存不了,保存后消失
解决方案:
1对于字符集问题有3种解决方式,设置字段字符集,表的字符集,数据字符集
其中设置字段字符集,表的字符集方法较笨,需要一个一个的设置,这里就简要说明下:
在navicat中选择要操作的表,选择“设计”,将光标放置在要修改的字段上,即可在下方修改该字段的字符集
同上,选择”设计“后,在选项中可以看到字符集一栏,修改后就完成了表的字符集修改
最后说下修改数据库的默认字符集,修改数据库的默认字符集必须在创建数据库的时候完成,如果数据库中已存在其他字符集的表,字段,则修改不会生效
如下图,在新建数据库时设置字符集
2.对于外键约束保存不了或者保存后消失的,有两个原因
1)数据库的FOREIGN_KEY_CHECKS=0;所有外键约束被禁用了
查看当前FOREIGN_KEY_CHECKS的值可用如下命令
SELECT @@FOREIGN_KEY_CHECKS;
之后再用SET FOREIGN_KEY_CHECKS=1;
来启动外键约束.
2)在 MySQL 中只有 InnoDB 类型的表才支持外键与存储过程
所有要建立外键的字段必须建立索引
创建数据库时设置表类型为InnoDB
CREATE TABLE `roottb` (
`id` INT(11) UNSIGNED AUTO_INCREMENT NOT NULL,
`data` VARCHAR(100) NOT NULL DEFAULT '',
PRIMARY KEY (`id`)
) TYPE=InnoDB;
Copy after login
在Navicat中,新建表时,在选项中设置引擎为InnoDB
CREATE TABLE `roottb` ( `id` INT(11) UNSIGNED AUTO_INCREMENT NOT NULL, `data` VARCHAR(100) NOT NULL DEFAULT '', PRIMARY KEY (`id`) ) TYPE=InnoDB;

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Navicat Keygen Patch is a key generator that activates Navicat Premium, allowing you to use the full functionality of the software without purchasing a license. How to use: 1) Download and install Keygen Patch; 2) Start Navicat Premium; 3) Generate the serial number and activation code; 4) Copy the key; 5) Activate Navicat Premium, and Navicat Premium can be activated.

How to check if Navicat is activated: View the Registration Information section in the "About Navicat" of the Help menu: Activated: Show valid registration information (name, organization, expiration date) Not activated: Show "Not Registered" or "Register Information Not Available" Check the activation icon in the toolbar: The green icon indicates that the active observation trial period countdown: The trial version will show the countdown at startup, the activated version will not view feature limitations: The trial version may limit advanced features, and the activated version will unlock all functions

How to import SQL files using Navicat? Open Navicat and connect to the database. Open the SQL Editor. Import SQL files. Set import options (optional). Perform import. Check the import results.

Export query results with Navicat can be performed step by step: 1. Select the data to export 2. Select the export format: CSV, Excel, XML, or JSON 3. Configure the export options: Select columns, separators, and filters 4. Select the save location 5. Start exporting 6. Verify the results

You can create a new MySQL connection in Navicat by following the steps: Open the application and select New Connection (Ctrl N). Select "MySQL" as the connection type. Enter the hostname/IP address, port, username, and password. (Optional) Configure advanced options. Save the connection and enter the connection name.

Navicat provides rollback functionality to undo database changes. The rollback steps are as follows: Connect the database to expand the database to be rolled back in the object browser. Right-click the table and select "Rolleepback" to select the rollback time point. Click "OK"

The steps to create a table in Navicat include: Open and connect to the database right-click the database name and create a new table to set the table properties (table name, storage engine, character set, sorting rules) Add fields (field name, data type, length, empty value, default value) Set the primary key (check the "Primary Key" check box) Set the foreign key (select the columns associated with the reference table and the foreign key) Save the table Click OK

To resolve errors when Navicat runs SQL files, follow these steps: 1. Check for SQL syntax errors; 2. Make sure the database connection is established; 3. Check file encoding; 4. Adjust server settings; 5. Check temporary space; 6. Disable certain plugins; 7. Contact Navicat Support if necessary.
