What is the correct syntax for executing a .sql script on a MySQL command line?

I'm confused. From the links I saw online, the command to execute the script text file is as follows:

mysql> --user=root --password=admin --database=zero <query.sql

However, when I ran this, an error with the mySQL syntax (error 1064) was indicated on the command line. I saved the query.sql script file in the program files C: ... \ MYSQL \ MYSQL Server5.1 .. (which folder directory does mySQL.exe command line terminal contain)

Then I did the following:

 mysql> USE db1 \g
 mysql> source <query.sql \g

It also does not work; The command line gave me the same error. My mysql version is different from other versions i have seen. As you can see, you should add '\ g' at the end of each request.

Please help and let me know if the description is not very clear .. thanks

Editorial: So, this is the code that I have inside query.sql:

CREATE TABLE IF NOT EXISTS 'db1'(
'id' int(255) NOT NULL auto_increment,
'date' date NOT NULL,
'title' varchar(255) NOT NULL,
'introtext' text NOT NULL,
'maintext' text NOT NULL,
PRIMARY KEY ('id')
)
+3
3

: 'db1'. backquotes, , date, date. ; :

CREATE TABLE IF NOT EXISTS db1(
  id int(255) NOT NULL auto_increment,
  `date` date NOT NULL,
  title varchar(255) NOT NULL,
  introtext text NOT NULL,
  maintext text NOT NULL,
  PRIMARY KEY (id)
) ;
+2

SQL :

\. query.sql

, , :

mysql --user=root --password=admin --database=zero < query.sql
+5

You need to specify the database so that the operator is like: -

USE (DATABASE NAME)

So replace the name (DATABASE NAME) with the database name

0
source

All Articles