Batch processing of SQL statements. There are two methods to execute the SQL statement script in linux: one is to execute the SQL statement script in the local windows system, the mysql server needs to be installed, and the environment variable needs to be configured, I will not talk about it here. There are a lot of searches on the Internet.
Focus on the second method: using the linux operating system
1. firstCopy the. SQL script file to the server where the database to be operated is located,You can use the rz command to upload files.
2.LinuxThe system runs the command to connect to mysql. #Mysql-h localhost-u root (login name)-pThe system will prompt you to enter the password and connect to the database successfully. Welcome to the MySQL monitor.
3. run the show databases command to check whether the database operated on the waist exists. If the SQL statement in the script is to operate a certain data, directly execute the command mysql>Source test. SQLThe script is successfully executed.
4. if you want to operate a table in a database, first enter the database, mysql>Use database nameAnd then execute the command mysql>Source test. SQLThe script is successfully executed.
Preface: By the way, I encountered a problem in the middle. my SQL statements contain Chinese characters and I found garbled characters in data writing. here is a good solution.: Use Notepad or other text tools to change the encoding format of SQL files
1. Use Notepad (or UE) to open the exported SQL file;
2. save this file. Open the "save as" dialog box and select UNICODE encoding as the encoding format in the dialog box.
3. copy the script file to the server where the database to be operated is located and run the source command again.