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
Related
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!!!!!
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'm running the following query from the command line in Raspbian:
mysql -u $NAME -p $PASS Tweets -e "SELECT count(*) FROM raw_tweets;"
And it is outputting the following. I'm sure it's a setting somewhere, but all of my searching has been fruitless. Thanks in advance for the help.
mysql Ver 14.14 Distrib 5.5.43, for debian-linux-gnu (armv7l) using readline 6.2
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.)
-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.
--auto-vertical-output
Automatically switch to vertical output mode if the
result is wider than the terminal width.
-B, --batch Don't use history file. Disable interactive behavior.
(Enables --silent.)
--character-sets-dir=name
Directory for character set files.
--column-type-info Display column type information.
-c, --comments Preserve comments. Send comments to the server. The
default is --skip-comments (discard comments), enable
with --comments.
-C, --compress Use compression in server/client protocol.
-#, --debug[=#] This is a non-debug version. Catch this and exit.
--debug-check Check memory and open file usage at exit.
-T, --debug-info Print some debug info at exit.
....... (Abbreviated, above should give enough of an example)
Your syntax is almost right, you forgot the add the database name parameter. Try this:
mysql -u $NAME -p $PASS -e "SELECT count(*) FROM raw_tweets" yourDBname
If Tweets is your database name, try this:
mysql -u $NAME -p $PASS -e "SELECT count(*) FROM raw_tweets" Tweets
Where $NAME and $PASS is your username and password with grants both for the database and the table.
No need of the semicolon. If you are running just one select 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.
I'm using MySql 5.5 on Mac 10.7.5. From the shell (I'm using bash), I'd like to be able to run a command o truncate data in all tables. Also, I'd like to enter a single command that won't prompt me for a password. I've tried this, that I found on another SO post, but no dice. What is a shell command I can use to truncate all database table data?
mysql -umyuser -p -e 'SET FOREIGN_KEY_CHECKS = 0; show tables' my_db | while read table; do mysql -e -umyuser -p "truncate table $table" my_db; done
Enter password:
mysql Ver 14.14 Distrib 5.5.25, for osx10.6 (i386) using readline 5.1
Copyright (c) 2000, 2011, 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.)
-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.
--auto-vertical-output
Automatically switch to vertical output mode if the
result is wider than the terminal width.
-B, --batch Don't use history file. Disable interactive behavior.
(Enables --silent.)
--character-sets-dir=name
Directory for character set files.
--column-type-info Display column type information.
-c, --comments Preserve comments. Send comments to the server. The
default is --skip-comments (discard comments), enable
with --comments.
-C, --compress Use compression in server/client protocol.
-#, --debug[=#] This is a non-debug version. Catch this and exit.
--debug-check Check memory and open file usage at exit.
-T, --debug-info Print some debug info at exit.
-D, --database=name Database to use.
--default-character-set=name
...
You can dump database without data:
mysqldump -u myuser -p --databases --add-drop-database --no-data my_db > my_db.sql
And restore it after that
mysql -u myuser -p < my_db.sql