Home > Database > Mysql Tutorial > body text

How to Execute an SQL Script from a Text File in MySQL?

Patricia Arquette
Release: 2024-11-12 17:45:02
Original
497 people have browsed it

How to Execute an SQL Script from a Text File in MySQL?

Executing SQL Scripts in MySQL

Problem: You're trying to execute an SQL script from a text file in MySQL but receiving an error.

Original Problem Statement:

"I want to execute a text file containing SQL queries in MySQL. I tried source /Desktop/test.sql and received:

mysql> . \home\sivakumar\Desktop\test.sql ERROR: Failed to open file '\home\sivakumar\Desktop\test.sql', error: 2
Copy after login

Answer:

To execute an SQL script from a text file in MySQL, you must use the correct syntax. Instead of source /Desktop/test.sql, use:

mysql> source \home\user\Desktop\test.sql;
Copy after login

Detailed Explanation:

In MySQL, you need to use the source command to read and execute an SQL script. Therefore, you can't use a period (.) as the command. In the correct syntax, source precedes the script's file path, which should be in full form with its absolute path (including the drive letter on Windows).

The above is the detailed content of How to Execute an SQL Script from a Text File in MySQL?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template