Encoding of mysql for mac
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Encoding of mysql for mac,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3367字,纯文字阅读大概需要5分钟。
内容图文
![Encoding of mysql for mac](/upload/InfoBanner/zyjiaocheng/480/0b84f86eeb3942e7b6220d5f7b246d29.jpg)
Solution: set all encoding in utf8
(in mysql using utf8 not utf-8)
Step1: check your encoding of mysql
mysql> show variables like "character%"; +--------------------------+-----------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | utf8 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | utf8 | | character_set_system | utf8 | | character_sets_dir | /usr/local/mysql-5.7.16-osx10.11-x86_64/share/charsets/ | +--------------------------+---------------------------+ 8 rows in set (0.00 sec)
Maybe your terminal would display diff from mine. That‘s OK and you have to set default encoding by modify the "my.cnf" file of mysql.
Step2 : Modify default encoding of mysql
http://www.cnblogs.com/jinjidedale/p/6183451.html
Step3: Change the database & table encoding
mysql> alter database testDB character set utf8; Query OK, 1 row affected (0.01 sec) mysql> alter table testTB convert to character set utf8; Query OK, 0 rows affected (0.06 sec) Records: 0 Duplicates: 0 Warnings: 0
Check your database & table encoding now and remember to restart your mysql if necessary.
mysql> show create database testDB;
+----------+-------------------+
| Database | Create Database |
+----------+-------------------+
| testDB | CREATE DATABASE `testDB` /*!40100 DEFAULT CHARACTER SET utf8 */ |
+----------+-------------------+
1 row in set (0.00 sec)
mysql> show create table testTB; +--------+----------------+ | Table | Create Table +--------+----------------+ | testTB | CREATE TABLE `testTB` ( `testNum` varchar(16) NOT NULL, `testName` varchar(32) NOT NULL, `testDate` date NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8 | +--------+----------------+ 1 row in set (0.01 sec)
Step4: change import file encoding
If you insert data by loading data infile, you have to makes sure the file has the same encdoing of utf8. The files I get from windows cannot directly use for importing. Mostly the files have Chinese character are encoding with gbk. You can open the file by Safari and click "view-encoding" to change into gbk. [cmd+A][cmd+c] copy the file into a new file opened by "text editor" and set preference of storing by encoding utf-8 in "open&store". Then the new file is totally can view in utf-8 with Chinese characters.
Finally you can import data form "test.txt" instead of insert data one by one.
mysql> load data local infile "/Users/.../Desktop/test.txt" into table testTB (testNum,testName,date); Query OK, 4 rows affected, 1 warning (0.00 sec) Records: 4 Deleted: 0 Skipped: 0 Warnings: 1
good luck!
Encoding of mysql for mac
标签:charset date cannot safari pre import convert result edit
本文系统来源:http://www.cnblogs.com/22Kon/p/6713768.html
内容总结
以上是互联网集市为您收集整理的Encoding of mysql for mac全部内容,希望文章能够帮你解决Encoding of mysql for mac所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。