據我所知,MySQL服務器沒有任何charset
命令要麼。用SET NAMES指定字符集,這是一個快捷方式來設置幾個相關變量(無論如何都可以使用SET
命令設置所有這些變量)。
你可能與官方命令行客戶端的命令困惑:
mysql> \h
For information about MySQL products and services, visit:
http://www.mysql.com/
For developer information, including the MySQL Reference Manual, visit:
http://dev.mysql.com/
To buy MySQL Enterprise support, training, or other products, visit:
https://shop.mysql.com/
List of all MySQL commands:
Note that all text commands must be first on line and end with ';'
? (\?) Synonym for `help'.
clear (\c) Clear the current input statement.
connect (\r) Reconnect to the server. Optional arguments are db and host.
delimiter (\d) Set statement delimiter.
ego (\G) Send command to mysql server, display result vertically.
exit (\q) Exit mysql. Same as quit.
go (\g) Send command to mysql server.
help (\h) Display this help.
notee (\t) Don't write into outfile.
print (\p) Print current command.
prompt (\R) Change your mysql prompt.
quit (\q) Quit mysql.
rehash (\#) Rebuild completion hash.
source (\.) Execute an SQL script file. Takes a file name as an argument.
status (\s) Get status information from the server.
tee (\T) Set outfile [to_outfile]. Append everything into given outfile.
use (\u) Use another database. Takes database name as argument.
charset (\C) Switch to another charset. Might be needed for processing binlog with multi-byte charsets.
warnings (\W) Show warnings after every statement.
nowarning (\w) Don't show warnings after every statement.
由於您使用的PHP,而不是命令行客戶端,它不存在。
當然,設置編碼的mysqli方式是mysqli::set_charset()。根據PHP手冊:_注意:這(set_charset)是改變字符集的首選方式
僅供參考使用
SET CHARACTER SET utf8mb4;
聲明。不建議使用mysqli_query()來設置它(例如SET NAMES utf8)。請參閱MySQL字符集概念部分以獲取更多信息._ – RiggsFolly