您可以使用<条码>LOAD_FILE功能,该功能是在对Charles Sprayberry与上述链接的问题的答复中提供的。 这样做是为了:
mysql -p -u user -e "update my_table set body=load_file( /path/to/filename ) where id=x;" dbname
如果你不去做(例如,由于许可问题或原因),那么你通过使用Bash和号的特征来确定你的现有指挥,以不同方式解决你的问题:
Most special characters, such as newlines and whatnot, seem to be just fine inside single-quoted strings. The only characters that should be a problem are
(which would be interpreted as terminating the string) and
(which would be interpreted as introducing an escape sequence), and both of these can be addressed by prefixing a
(for example,
and \
are string literals denoting
and
, respectively). This sed
script inserts a
before any
or
:
s/( |\)/\1/g
您可以援引Bash等人的话:
sed s/( " " |\)/\1/g filename
(例如,如果<代码> 页: 1
a b c
d e f
然后>>>>>>>>//1/g filename
a \ b \ c
d e f
). But you can t just wrap the above in `...`
, because these characters are special to Bash as well, and it will get confused. (I m assuming you re using Bash?) Instead, you need to use $(...)
, which is a Bash notation that s equivalent to `...`
except that it better handles various details like this. (I recommend always using $(...)
over `...`
.) So your overall command would be:
mysql -p -u user -e "update my_table set body= $(sed s/( " " |\)/\1/g filename) where id=x;" dbname