A new library is created with the default encoding. Import utf8 encoded tables and data. The results are all garbled. Changing the encoding of the SQL file still does not work. Finally, we found that utf8 encoding was not set during database creation. As a result, the following records are recorded to solve the problem.
Database creation:
Create database 'mydb' default character set utf8 COLLATE utf8_general_ci;
Record related database operations:
Import SQL files
Mysql-h localhost-u root-p mydbname <data. SQL;
Export SQL
Mysqldump-h localhost-u root-p -- default-character-set = utf8 mydbname> data. SQL;
Table creation:
Drop table if exists 'mytablename ';
SET @ saved_cs_client =@@ character_set_client;
SET character_set_client = utf8;
Create table 'mytablename '(
'Id' int (10) unsigned not null auto_increment,
'Int10' int (10) unsigned not null,
'Char2' char (2 ),
'Varchar100' varchar (100) not null,
Primary key ('id ')
) ENGINE = MyISAM AUTO_INCREMENT = 1 default charset = utf8;
SET character_set_client = @ saved_cs_client;
Insert data:
Lock tables 'mytablename' WRITE;
Insert into 'mytablename' ('id', 'int10', 'char2', 'varchar100') VALUES (, "AB", "adsfsadf ");
Unlock tables;
Create a user (Set permissions and passwords)
Grant all privileges on *. * TO 'user' @ 'localhost' identified by '123 ′;
Grant all privileges on *. * TO 'user' @ '1970. 0.0.1 'identified by '123 ′;
All privileges indicates ALL permissions. Optional values: select, insert, update, delete, create, and drop.
*. * Indicates a database. A table.
Localhost is set to: %
Change Password:
Mysqladmin-u root-p password 456789
View All Users:
Select host, user from mysql. user;
Finally, in order to avoid garbled characters, file encoding, page encoding, database encoding, Application Server encoding, and operating system encoding should be unified.
Author: Kong Yun Wanqing