mySQL角色集和整理问题。
-
22-10-2019 - |
题
从表中选择时,我有一个表,我将无效的数据作为
mysql> select budgetID,StartDate,modifiedBy from Table_name order by budgetID desc limit 10;
+----------+---------------------+----------------------+
| budgetID | StartDate | modifiedBy |
+----------+---------------------+----------------------+
| 364 | $091-24-68 27:49:32 | -9187343239835811836 |
| 363 | NULL | -9187343239835811840 |
| 362 | $091-24-69 14:21:19 | -9187343239835811840 |
| 361 | $091-24-69 14:21:19 | -9187343239835811840 |
| 360 | $091-24-69 14:21:19 | -9187343239835811840 |
| 359 | $091-24-69 14:21:19 | -9187343239835811840 |
| 358 | �301-32-83 19:54:95 | -9187343239835811840 |
| 357 | �301-32-83 19:54:95 | -9187343239835811840 |
| 356 | $091-24-69 05:61:82 | -9187343239835811840 |
| 355 | �301-32-83 10:95:58 | -9187343239835811840 |
+----------+---------------------+----------------------+
我已经插入了预算= 365的值
budgetID 351
StartDate 2012-02-01 00:00:00
modifiedBy 1055
但是,在选择结果时,我将获得无效的输出。
BudgitID是Primay关键的Bigint和Startdate的位置是DateTime,而Bigint则修改了。
和
mysql> show variables like "%character%";
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
mysql> show variables like "%colla%";
+----------------------+-------------------+
| Variable_name | Value |
+----------------------+-------------------+
| collation_connection | utf8_general_ci |
| collation_database | latin1_swedish_ci |
| collation_server | latin1_swedish_ci |
+----------------------+-------------------+
这背后的问题可能是什么??
当我创建了一个与此表相同结构并插入记录的表时,则选择“查询”显示结果正常。
解决方案
基于您的默认数据库编码, targin_set_database = latin1, ,您应该强迫客户使用Latin1。您的客户端当前在UTF8中,数据库似乎在Latin1中。这假设您的表也使用Latin1。
为了确保您的数据正确存储在MySQL中,您可以强迫MySQL客户端使用Latin1。
1 强迫客户使用拉丁语1
mysql -u root -p --default-character-set=latin1 nameofthedatabase
然后运行您的选择语句以验证字符格式
select budgetID,StartDate,modifiedBy from Table_name order by budgetID desc limit 10
2 使用Latin1备份数据库
您也可以使用相同的选项转移数据库
mysqldump -u root -p --default-character-set=latin1 nameofthedatabase > nameofthedatabase.sql
然后,您可以使用标准的文本编辑器(例如TextPad或gedit)查看字符是否正确编码。
整理是一组规则,这些规则决定了行的排序方式以及如何比较。整理不会影响您当前遇到的问题的编码。
如果两个选项仍然给您奇怪的符号,则首先可能未正确格式化导入文件。
不隶属于 dba.stackexchange