SQL statement batch processing: execute SQL script _ MySQL in linux

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.