I am trying to restore an mysql database using
mysql -u root -p databasename < dumpfile.bak
I get this 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 'mysql Ver 14.14 Distrib 5.7.9, for Win64 (x86_64)
Copyright (c) 2000, 2015, Ora' at line 1
The database is created and is correct looking at it "Show columns from table name" the dumpfile is in the mysql bin folder.
The dump file was created using mysqldump -u root -p databasename > dumpfile.bak
Here are the first few lines of the dumpfile:
mysql Ver 14.14 Distrib 5.7.9, for Win64 (x86_64)
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Usage: mysql [OPTIONS] [database]
-?, --help Display this help and exit.
-I, --help Synonym for -?
--auto-rehash Enable automatic rehashing. One doesn't need to use
'rehash' to get table and field completion, but startup
and reconnecting may take a longer time. Disable with
--disable-auto-rehash.
(Defaults to on; use --skip-auto-rehash to disable.)
Can anyone help?
I found the issue, when progman talked about the dbfile, after I posted it, I took another look and found that it was not the correct version of the file. I thought the error was in the query not the file. Thanks for the help!!!!!
Related
I am trying to connect to a remote MySQL server:
C:\Program Files\MySQL\MySQL Server 5.7\bin>mysql.exe -u USERNAME -p PASSWORD -h www.example.net DB_NAME
The result:
mysql.exe Ver 14.14 Distrib 5.7.17, for Win64 (x86_64)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Usage: mysql.exe [OPTIONS] [database]
-?, --help Display this help and exit.
-I, --help Synonym for -?
--auto-rehash Enable automatic rehashing. One doesn't need to use
'rehash' to get table and field completion, but startup
and reconnecting may take a longer time. Disable with
--disable-auto-rehash.
(Defaults to on; use --skip-auto-rehash to disable.)
-A, --no-auto-rehash
No automatic rehashing. One has to use 'rehash' to get
table and field completion. This gives a quicker start of
mysql and disables rehashing on reconnect.
... and so on, the help page is long.
Why does the mysql.exe utility ignore my commands?
The password must have no space before it:
mysql.exe -u USERNAME -pPASSWORD
I'm baffled as to where I'm going wrong with the following mysql command in my bash script to get a SELECT statement out in HTML format.
#!/bin/bash
dbhost="localhost"
dbname="unicentaopos"
dbuser="user"
dbpass="pass"
mysql -h $dbhost -u $dbuser -p $dbpass -H -e "SELECT NOW();" $dbname > /home/imperial/.scripts/test.txt
Everything is identical to my script, except for the credentials for obvious reasons. I have also tried hard coding the vars into the command - same results.
I cannot see anything wrong with what I've done, but the text file produced just contains mysql usage options:
mysql Ver 14.14 Distrib 5.7.25, for Linux (x86_64) using EditLine wrapper
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Usage: mysql [OPTIONS] [database]
-?, --help Display this help and exit.
-I, --help Synonym for -?
etc etc etc etc.....
Can anyone tell me what's wrong?
is the dbhost variable accessed correctly?
#dbhost -> $dbhost
I am using wampserver 64 bit. I started the MySQL console via the wamp tray menu icon and executed this command as seen in the documentation.
mysqldump magento_live > dump.sql;
Result:
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 'mysqldump magento_live > dump.sql' at line 1
I also tried it like in this answer:
mysqldump -u root -p root -h localhost magento_live > magentoLiveDump.sql;
Result:
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 'mysqldump -u root -p root -h localhost
magento_live > magentoLiveDump.sql' at line 1
I am using MySQL 5.7
I tried it via CMD by using this command:
C:\wamp64\bin\mysql\mysql5.7.21\bin>C:\wamp64\bin\mysql\mysql5.7.21\bin\mysql.exe mysqldump magento_live > test.sql
A file is created, but this is the content:
C:\wamp64\bin\mysql\mysql5.7.21\bin\mysql.exe Ver 14.14 Distrib
5.7.21, for Win64 (x86_64) Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective owners.
Usage: C:\wamp64\bin\mysql\mysql5.7.21\bin\mysql.exe [OPTIONS]
[database] -?, --help Display this help and exit. -I,
--help Synonym for -? --auto-rehash Enable automatic rehashing. One doesn't need to use
'rehash' to get table and field completion, but startup
and reconnecting may take a longer time. Disable with
--disable-auto-rehash.
(Defaults to on; use --skip-auto-rehash to disable.) -A, --no-auto-rehash
[...]
The command mysqldump will not run from MySQL CLI, you will have to run it from the windows command prompt (CMD) or from the Powershell.
You have to start a CMD or Powershell and navigate to the bin folder inside the MySQL directory (wamp64\bin\mysql\mysql5.7.21\bin).
Then you have to execute the command like this:
mysqldump -u[USERNAME] -p target_database > target_dump_name.sql
Important: There is no space allowed between the option and the value.
WRONG: mysqldump -u root -p target_database > target_dump_name.sql
CORRECT: mysqldump -uroot -p target_database > target_dump_name.sql
Example
CMD:
mysqldump -uroot -p magento_live > magento_live_dump.sql
Powershell:
.\mysqldump -uroot -p magento_live > magento_live_dump.sql
Note: In Powershell you will have to add .\ before the command.
I am trying to access mysql via command line, but when I enter the command to access my DB, I get the mysql --help text as an output. Here is what I am typing in:
mysql -h localhost -u USER -p PASSWORD DB_NAME
I have confirmed all of my credentials are correct, but when I run that, I get the following:
mysql Ver 14.14 Distrib 5.5.32, for Linux (x86_64) using readline 5.1
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Usage: mysql [OPTIONS] [database]
-?, --help Display this help and exit.
-I, --help Synonym for -?
--auto-rehash Enable automatic rehashing. One do...
I have also tried running it using php exec. I see the same output that way also. Anyone have any thoughts on why this is occurring?
Remove the space between your -p flag and your actual password, or use --password=PASSWORD. From the man page:
If you use the short option form (-p), you cannot have a space between the option and the password.
Don't include PASSWORD in the command. The "-p" is all you need. It will prompt you for the password without showing the characters you type.
good day all,
please i am new to bash scripting and i am having some challenges with my bash script for connecting to a mysql server to reteive information. this is my script:
#! /bin/bash
MYSQL_USER="root"
MYSQL_PASSWORD="bibson13"
MYSQL_DATABASE="fredhosting"
MYSQL="/usr/bin/mysql –u$MYSQL_USER –p$MYSQL_PASSWORD -D$MYSQL_DATABASE"
$MYSQL -ss -e "select name,email,username,password from free_users where id_user=( select max(id_user) from free_users )"
but when i try to run it i keep getting this:
/usr/bin/mysql Ver 14.14 Distrib 5.5.28, for debian-linux-gnu (i686) using readline 6.2
Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Usage: /usr/bin/mysql [OPTIONS] [database]
please i really don't know what am doing wrong. i would be most grateful if anyone could help me with some information on what to do, thank you.
The main problem is that you have some broken characters. Specifically, where you meant to type -u and -p (with hyphens), you instead have –u and –p (with en-dashes). This probably results from copying-and-pasting via a word-processor such as Microsoft Word (which is never a good idea). Once you change those en-dashes back to hyphens, you should be O.K.
You have 2 invalid characters into your MYSQL variable (E2 80) before each "-" sign.
Try to cleanup the line.