问题描述:

I am confused. From references I have seen online, the command to execute a text file script is this:

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

However when I ran this, the command line said theres an error with mySQL syntax (error 1064).

I saved the query.sql script file within the C:program files...\MYSQL\MYSQL Server5.1.. (whichever folder directory that contains the mySQL command line terminal .exe)

I then did this:

 mysql> USE db1 \g

mysql> source <query.sql \g

It also doesnt work; command line gave me the same error. mySQL version I have is different than other versions I have seen. As you can see, you have to add '\g' at the end of every query.

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

EDITED:

So this is the code I have inside the 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')

)

网友答案:

Remove the quotes: 'db1'. Use backquotes where necessary, like for field called date to identify it from type date. And add a ; at the end of the statement:

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)
) ;
网友答案:

You can run an SQL file from within the client with:

\. query.sql

Alternatively, if you're not already in the client, you can use the following from the command line:

mysql --user=root --password=admin --database=zero < query.sql
网友答案:

You need to specify the DB so a statement like:-

USE (DATABASE NAME)

So above replace the (DATABASE NAME) with the name of the Database

相关阅读:
Top