mysql export import Chinese table solution

  • 2020-05-14 05:06:17
  • OfStack

In the development process, mysql export will often be used to import Chinese table, this article will introduce how to use it in detail, you can refer to it
1. First, export for utf8:
(1) export all tables of the source database:
 
mysqldump -u root -p password  --socket=mysql.sock --default-character-set=utf8 --set-charset=utf8 --hex-blob --databases  The database name  > utf8.sql 

(2) modify the sql file and delete the command to create the database contained in the header of the file
(3) login to the target database
mysql-uroot-p password -- default-character-set =utf8 --socket= mysql.sock-A
Note: you must specify a character set login, and the specified character set must correspond to the character set specified at the time of export
(4) delete the database (if any)
drop database database name;
(5) create the database and save it as utf8 storage format, and import it
 
create database  The database name  charset=utf8; 
use  The database name ; 
source utf8.sql; 

After this import, the Chinese table may be garbled. So, to use the following method, import the Chinese table.

2. Import and export Chinese table:
 
# export  
mysqldump -u root -p password  --socket=mysql.sock --default-character-set=gbk --set-charset=gbk --hex-blob  The database name   The name of the table 1  The name of the table 2  ...  > gbk.sql 
# The import ( When importing a table, if the table already exists, it will be deleted first and then imported, so there is no need to delete the existing table in advance ) 
mysql -uroot -p password  --default-character-set=gbk --socket=mysql.sock -A <<EOF 
use  The database name ; 
source gbk.sql 
EOF 

Related articles: