mysql syntax error near expected new line in terminal mac - mysql

I am running the following command as given on web to connect the mysql data base but it gives syntax error new line expected here is the command i am entering.
mysql -<hivelettest.c0e9graawyhr.us-west-2.rds.amazonaws.com -p 3306 -u <user> -p <pass>

The <> parts of the command were given to show where the username and password should go. They shouldn't be in the command:
mysql -hmydbserver.co.uk -P3306 -u username -pmypassword

Try this, and make sure that there is no space between -u or -p. And if you are using PORT you need to write it differently. The password parameter must then be --password=
mysql -hmydbserver.co.uk -P 3306 -uUsername --password=yourpassword
Since 3306 is the standard one you could leave it out, then you can write it like this.
mysql -hmydbserver.co.uk -uUsername -pYourpassword
If you want to pass with a command, do it like this.
mysql -hmydbserver.co.uk -P 3306 -uUsername --password=yourpassword nameofdatabase
-e "SELECT * FROM tablename"

Related

Connect to different port using MySql Command Line Client

By default I am being connected to port 3309.I need to connect to port 3307.How do I do that?
Use -P parameter, like this:
mysql -h 127.0.0.1 -P 3307 -u user_name -p database_name
Important: if you connecting to localhost - use -h 127.0.0.1, NOT localhost, because MySQL will connect by file socket, not by TCP
From command line, assuming you are on the same host, have you tried :
mysql --user root --password (mypassword) --host=localhost --port=33061
In server name specify custom port when not using default one (you can imply it only when is the standard mysql port 3306)
$servername = "localhost:33061";
you can use -P (uppercase) or --port=portnumber
sample
mysql -u root -P 13306 -p databasename
or
mysql -u root --port=13306 -p databasename
Enter this command changing your details.
after that MySQL requests the password for the connection, then enter the password.
mysql --user=user1 --host=127.16.38.1 --port=25060 -p
especially consider about -p and double Hyphen --
I am giving simple way, one liner which summarizes.
mysql -u root -p --port=3316 // I have MySQL port 3316, instead of default 3306
If the --port=3316 is not provided, then MySQL Cli protocol will try with the default port, without asking.
For any other user
mysql -u anotheruser -p --port=3316

Typing in MySQL Password Through Shell Script

So I'm trying to run the following lines as a shell script
mysql -u root -p -h myserver
connect testdb
SELECT * FROM testtable
However, after I type the initial "mysql -u root -p" it asks for a password rather than running the entire thing automatically. My question is, is there some line I can add to my shell script to automatically type the password in and press "Enter".
Thanks.
Try below line
echo "SELECT * FROM testtable" | mysql -h myserver -u root -pPASSWORD testdb
replace PASSWORD with your mysql password.

How to unblock with mysqladmin flush hosts

I have gone through similar cases listed here but it doesn't seem to work.
I was using MySQL Workbench to establish a connection with my database which is hosted on another server. Tried a few times and unable to connect followed by this error. I am confused as to where I should even do this flush. On PhpMyadmin under the SQL query? Cos when I tried to input the following command, it returns as syntax error. I am using a windows OS thus no shell shell scripting for me to input this information either. I am accessing the database temporarily via Cpanel/ phpmyadmin now.
Please help to tell where I should input this data and if my syntax is wrong. Thanks for help.
mysqladmin flush-hosts;
or
mysqladmin -umyname -pmypassword flush-hosts;
My error message as follows:
Failed to connect to MYSql at 192...* with user myName
Host 'host-92...*.as13285.net' is blocked because of many connection
errors; unblock with 'mysqladmin flush-hosts'
mysqladmin is not a SQL statement. It's a little helper utility program you'll find on your MySQL server... and "flush-hosts" is one of the things it can do. ("status" and "shutdown" are a couple of other things that come to mind).
You type that command from a shell prompt.
Alternately, from your query browser (such as phpMyAdmin), the SQL statement you're looking for is simply this:
FLUSH HOSTS;
http://dev.mysql.com/doc/refman/5.6/en/flush.html
http://dev.mysql.com/doc/refman/5.6/en/mysqladmin.html
You should put it into command line in windows.
mysqladmin -u [username] -p flush-hosts
**** [MySQL password]
or
mysqladmin flush-hosts -u [username] -p
**** [MySQL password]
For network login use the following command:
mysqladmin -h <RDS ENDPOINT URL> -P <PORT> -u <USER> -p flush-hosts
mysqladmin -h [YOUR RDS END POINT URL] -P 3306 -u [DB USER] -p flush-hosts
you can permanently solution your problem by editing my.ini file[Mysql configuration file]
change variables max_connections = 10000;
or
login into MySQL using command line -
mysql -u [username] -p
**** [MySQL password]
put the below command into MySQL window
SET GLOBAL max_connect_errors=10000;
set global max_connections = 200;
check veritable using command-
show variables like "max_connections";
show variables like "max_connect_errors";
You can easily restart your MySql service. This kicks the error off.

Terminal mysql queries

I'm looking to use terminal to execute mysql queries. I currently connect to a sql db via the sql workbench but would like to do this via terminal. Is this possible?
I've installed mysql via homebrew
when I hit mysql in terminal it says command not found, maybe I need to do something else besides the homebrew setup?
Go to the directory:
mysql/bin
To execute the query from command line:
mysql -u [username] -p [dbname] -e [query]
example:
mysql -u root -p database -e "select * from user"
mysql --help
You can do also:
cat dump.sql | mysql -u user -p password database
Or:
echo "select * from abc;" | mysql -u user -p password database

how to get DB backup script from Remote Server in MySQL using command-line utility?

Can anybody tell me that how to get DB backup script from Remote Server in MySQL using command-line utility?
I'm using a command as follows, but not working:
C:\>mysqldump -h <server ip> -u <user-id> -p <password> <db name> >
E:\dumpfilename.sql
The syntax for the password is wrong. You need to write the password immediately after the -p, without a space. That's why the password is interpreted as the database name.
Write this instead:
C:\>mysqldump -h <server ip> -u <user-id> -p<password> <db name> >
E:\dumpfilename.sql
Notice how there is no space after -p. An example would be -phunter2, where the password is "hunter2".