在utf-8中从bash写入Mysql DB
作者:互联网
我有问题用utf-8编码写入mysql DB.我的应用程序有点复杂,所以我会尝试尽可能具体. (我的申请要求斯洛伐克特殊字体(有utf-8),如ľščťžýáí等.
我正在运行debian.我相信我的语言环境设置正确,但要确定:
root@radiator:/var/scripts# locale
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
LANG=sk_SK.UTF-8
LANGUAGE=sk_SK.UTF-8:cs_CZ.UTF-8
LC_CTYPE="sk_SK.UTF-8"
LC_NUMERIC="sk_SK.UTF-8"
LC_TIME="sk_SK.UTF-8"
LC_COLLATE="sk_SK.UTF-8"
LC_MONETARY="sk_SK.UTF-8"
LC_MESSAGES="sk_SK.UTF-8"
LC_PAPER="sk_SK.UTF-8"
LC_NAME="sk_SK.UTF-8"
LC_ADDRESS="sk_SK.UTF-8"
LC_TELEPHONE="sk_SK.UTF-8"
LC_MEASUREMENT="sk_SK.UTF-8"
LC_IDENTIFICATION="sk_SK.UTF-8"
LC_ALL=
我有bash脚本应该写文本(用斯洛伐克语写到DB.)(第一个哈希字符是因为debian不知道使用BOM,还是不知道如何处理它)
#
#!/bin/bash
table=$1
cycle=$2
sstart=$3
eend=$4
dbtext=$(cat /var/www/vids/$5/vars/$5.recogn.p.tmp2)
qry="INSERT INTO \`video\`.\`$table\` (\`DB_ID\` , \`LNX_ID\` , \`STIME\` , \`ETIME\` , \`TEXT\` ) VALUES ( NULL , '$cycle', '$sstart', '$eend', '$dbtext');"
mysql --host=localhost --database 'video' --user=uzivatel --password=heslo << eof
$qry
eof
这是提到的tmp2文件的内容(此文件的编码是utf-8):
Tá žena držal poznali poznal jeho rodičov poznali podsvetie hodváb ulsteru mám ostatných tak veľmi dobre ako boli pre nato že sa bude vydávať ale skóre nevyšlo to potom zas nasťahovala.
在phpmyadmin中它看起来像:
Tá žena držal poznali poznal jeho rodiÄov poznali podsvetie hodváb ulsteru mám ostatných tak veľmi dobre ako boli pre nato že sa bude vydávaÅ¥ ale skóre nevyÅ¡lo to potom zas nasÅ¥ahovala.
(此字段中的编码为utf8_slovak_ci)(谷歌浏览器编码为utf8).
我花了整整一天来谷歌这个,我不知道什么是问题.
请你帮助我好吗 ?我知道你是最棒的..
标签:byte-order-mark,bash,mysql,utf-8 来源: https://codeday.me/bug/20190728/1566579.html