The below query works
SELECT *
FROM some_table
LIMIT 1
INTO outfile 'some_file.txt';
but how would you write the result of this statement to file
SHOW ENGINE INNODB STATUS INTO OUTFILE 'some_file.txt'
or any other show statements, getting error using into outfile?
Error message:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INTO OUTFILE "some_file.txt"' at line 1
You CANNOT. INTO OUTFILE can be used only with SELECT STATEMENT... hence you're getting 1064 (syntax-error). Please refer to the documentation here: https://dev.mysql.com/doc/refman/5.1/en/select-into.html
It always says-"SELECT ... INTO OUTFILE..."
You need to use console in order to get output of SHOW commands or anything apart of 'SELECT' statement. Here's how you do it:
Follow the syntax below:
mysql --user root --password=sunny -e"show databases">"D:\\test\\OutFile.txt";
Above statement will give your all the databases in outfile.
mysql --user root --password=sunny --database=mydb -e"describe myTable">"D:\\test\\OutFile.txt";
This will output the description of your table.
HTH !
Related
I'm using MySql v8.0 and I'm having a syntax error for a simple command like this:
SELECT * FROM System
Then I have an error like this:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'System
select * from System' at line 1
But if I change my command to
SELECT * FROM someSchema.System
it works.
My colleagues said they have no problem of SELECT * FROM System but their MySql version is 5.7.
I'd like to see if this is a version change between MySql 5.7 and 8.0 or there is some setting for my MySql setup? How can I avoid explicitly writing my schema name?
System is a reserved word, try with
SELECT * FROM `System`
I am able to create databases and tables using the User Interface in phpMyAdmin , but when I do the same using MySQL commands , It does not work. I get this error :
SQL query:
DROP DATABASE 'alphacrm'
MySQL said: Documentation
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''alphacrm'' at line 1**
don't use quote
DROP DATABASE alphacrm;
my sql object don't need quotes eventually use backtics for reversed word and compite named eg:
`my obj`
I am running my store under Xcart and I get following error on top of web browser:
INVALID SQL: 1064 : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'OPTION SQL_MAX_JOIN_SIZE=1073741824' at line 1
SQL QUERY FAILURE:SET OPTION SQL_MAX_JOIN_SIZE=1073741824
INVALID SQL: 1064 : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'OPTION SQL_BIG_SELECTS=1' at line 1
SQL QUERY FAILURE:SET OPTION SQL_BIG_SELECTS=1
INVALID SQL: 1064 : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'OPTION SQL_BIG_SELECTS=1' at line 1
SQL QUERY FAILURE:SET OPTION SQL_BIG_SELECTS=1
what cause this so I can clear the error?
thanks!
It seems your MySQL server has been updated.
Replace all strings like
'SET OPTION SQL_MAX_JOIN_SIZE'
to these
'SET SESSION MAX_JOIN_SIZE'
A command for the unix-based hostings
sed -i 's/SET OPTION /SET SESSION /' $(grep --include='*.php' -rl 'SET OPTION ' ~/www/xcart_4_6_x)
It needs to check the xcart php scripts where this query is executed and OPTION to be replaced with SESSION for the errors like
SQL QUERY FAILURE:SET OPTION SQL_BIG_SELECTS=1
Also, as for
SQL QUERY FAILURE:SET OPTION SQL_MAX_JOIN_SIZE=1073741824
it might worth to change it just to db_query("SET max_join_size=1073741824");
It works for some xcart installations so please report if it helps to your project as well, thanks
I have create a shell script to automate my database migration from host to host, that extracts my Multi WordPress site tables into separated sql files, so I can decide what site I will migrate each time.
So in my shell script I have the following code:
schema="internet-safe"
PROJECT_FOLDER_NAME="internet-safe"
vagrant_export_folder="/var/www/projects/${PROJECT_FOLDER_NAME}/database/tmp"
query="mysql -uroot -proot -e \"SELECT blog_id AS ID, path AS Slug FROM ${schema}.wp_blogs "
query="$query INTO OUTFILE '$vagrant_export_folder/blogs.csv' "
query="$query FIELDS TERMINATED BY ',' "
query="$query ENCLOSED BY '\\\"' "
query="$query LINES TERMINATED BY '\n' \" > /dev/null"
vagrant ssh --command "cd $vagrant_export_folder && $query"
But by executing this script I get the following error:
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-safe.wp_blogs INTO OUTFILE '/var/www/projects/internet-safe/database/tmp/blogs' at line 1
Connection to 127.0.0.1 closed.
An the problem is the dash in the schema name internet-safe. Is there a way to correct this issue ?
I know that there is an option, to just rename the schema, but, unfortunately I run on unstable vagrant, on xUbuntu, that has destroy my database several times, while I try to provision modifications in my databases.
I also have try the following combinations but I get error messages like the following:
`${schema}`.`wp_blogs`
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INTO OUTFILE '/var/www/projects/internet-safe/database/tmp/blogs.csv' FIELDS TE' at line 1
`${schema}`.wp_blogs
ERROR 1046 (3D000) at line 1: No database selected
`${schema}.wp_blogs`
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INTO OUTFILE '/var/www/projects/internet-safe/database/tmp/blogs.csv' FIELDS TE' at line 1
Best option would be of course to simply rename your database.
Usually when special characters appear in schema/table/column names, you can fix this with backticks. Since you're trying to run a shell script, it will interpret anything within backticks as a command, unfortunately.
In MySQL you can set the sql_mode "ANSI_QUOTES". Do so as administrator/root (in MySQL) with
mysql> SET GLOBAL sql_mode="ANSI_QUOTES";
Check first, if you have any modes set already with
mysql> SHOW VARIABLES LIKE 'sql_mode';
If there are already modes set, include those in the SET GLOBAL sql_mode statement (separated by ,).
You can also set this option in your my.cnf file, so that this mode is applied every time you start your MySQL server.
The effect is, that " is also allowed as identifier quote character. But be careful, that you don't use " in queries to specify any text, use single-quotes there instead.
read more about it here
I am restoring a mysqldump file to another server. The versions are close, so I didn't expect any problems. I get:
:/var/backups$ sudo mysql -f -u root -p dbasename < backup.sql
Enter password:
ERROR 1064 (42000) at line 542: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' Current\n * President/CEO at Echoingwalls.com\n * Develope' at line 1
Other's solutions with this error message haven't been helpful. How can I detect if my back up is corrupt? I am pretty sure the versions of MySQL have been pretty close (both 5.x).
Any specific instructions on how to restore this would be appreciated.
It seems like you may have an inconsistency between how your systems are escaping single quote;
... use near '' Current\n * Presi ....
^ Note the addtional quote
Do diagnose the problem compare both tables
show create table mytable
And campare the sql modes
SELECT ##GLOBAL.sql_mode;
SELECT ##SESSION.sql_mode;
For more help find the insert statement in the dump file and post the sql.