Fixed the problem of scrambled code when mysql was imported and restored

  • 2020-05-14 05:12:52
  • OfStack

Solutions:
Step 1: restore the database and tables in utf8 format (utf8 is recommended, as is gbk or gb2312)

 
CREATE DATABASE `shegongku` DEFAULT CHARACTER SET utf8 
CREATE TABLE `members` ( 
`uid` mediumint(8) unsigned NOT NULL default '0', 
`username` varchar(15) NOT NULL default '', 
`password` varchar(40) NOT NULL default '', 
`salt` varchar(16) default NULL, 
`email` varchar(60) NOT NULL default '' 
) ENGINE=MyISAM DEFAULT CHARSET=utf8; 


Part 2, convert the encoding of sql file into utf8 format, which can be either notepad2 or UltraEditor, and then add 1 line set names utf8 to the sql file in line 1.

Part 3, import. In general, there will be no gargoyles. If you query the terminal cmd again and find it is still gargoyles, this is not a database problem, but a display problem. Enter set names gbk in the terminal, and the Chinese will be displayed normally

Related articles: