A solution to the problem of garbled code when importing from the command line to the mysql database

  • 2020-06-19 11:54:28
  • OfStack

Solutions:

Open the sql file and add the following in line 1 of the SQL file


/*!40101 SET NAMES utf8 */;

Save the SQL file as UTF-8 NO BOM

Upload the sql file via ftp and place it in the root directory

Go to your cPanel, see the icon cron jobs, click in, and select Advanced (Unix Style)

Since it only needs to be run once, Minute, Hour, Day and Month all fill in the specific time to be run, leaving a margin of two minutes (if the virtual host is not local, you can check the 1 host time on FTP), and Weekday fill in the * sign. Command fills in the command to run, which is the import command:
mysql-u username -p password [-ES37en database host] database < Database backup.sql

Assume that the remote host's IP is 10.0.0.1, the user name is root, and the password is 123. Type the following command:


mysql -h10.0.0.1 -uroot -p123

Note:
u and root do not need to add space, others are the same. For example, my Settings are as follows:


mysql -ucpanel123_cpuser -pcpanel -hlocalhost cpanel123_cp < /home/ your cpanel The user name /public_html/jia.sql

Then look at the imports in phpMyAdmin. It is very fast to import sql files in this way. Wish you success.


Related articles: