How to resolve backticks error while using -e with mysql client? - mysql

Hi I am trying run belo sql on Ubuntu terminal using MySQL client
mysql -u root \
-proot -e "SELECT * FROM knexus.redis_cache WHERE `key` LIKE '%hub.local%'"
I am getting below error
The program 'key' is currently not installed. You can install it by typing:
sudo apt-get install donkey
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 'LIKE '%hub.local%'' at line 1
However SQL run properly on MYSQL terminal.
I guess this might be issue character escaping issue, as I see sudo apt-get install donkey.

The ticks framing key cause the bash to treat key as a command and replace it by its output in the command. You could either try without them or put the whole command in single quotes and the %hub.local% in double quotes.

Related

syntax error with mysqldbcompare command

mysql -V is 5.5.54 for debian (Jessie).
I'm at the mysql command prompt trying to run this command:
mysqldbcompare --server1=root#localhost calendar_dup:calendar --run-all-tests
I get the following error:
ERROR 1064 (42000): You have an error in your SQL sytax; check manual that corresponds to your MySQL server version for the right syntx to use near 'mysqldbcompare --server1=root#127.0.0.1 calendar_dup:calendar --run-all-tests' at line 1
Needed to install via apt-get: https://packages.debian.org/jessie/mysql-utilities
Also, should be run from shell command line, not mysql command line.

Update MYSQL table via BASH script give syntax error

I'm trying to run an update query on a db server via bash command.
I have to update an IP field (which is sorted as a string) but i'm getting a syntax error...
ssh admin#192.168.3.240 "/usr/local/mysql/bin/mysql -D SMARTPARK -u parkuser -ppass -e 'update client SET online=0 where client_ip='192.168.42.11''"
I'm getting as 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 '.42.11' at line 1
which is the error?
Try to escape " character with \" to make sure you don't escape from the string you're sending to your DB.
In other words, try to put the following in the bash file you're executing:
ssh admin#192.168.3.240 "/usr/local/mysql/bin/mysql -D SMARTPARK -u parkuser -ppass -e \"update client SET online=0 where client_ip='192.168.42.11'\""

How to execute a "INSERT INTO" query to a remote database with linux command line?

I'm tryng to create a code in raspbian system to update a value in my database mySQL stored into my hosting server using a bash ".sh" scrypt.
this line won't to work but I don't know why...
mysql -h eliuslab.com -u user -pPassWord -D mydatabase -e "INSERT INTO 'home-IP' ('IP') VALUES ('192.168.1.2')"
And the output:
'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 ''home-IP' ('IP') VALUES ('192.168.1.2')' at line 1 '
this query works well in a GUI mySQL client, but what I want to do is to launch this action with my ".sh" bash scrypt.
Thank you so much :)
Okay I got the solution. I ran your script in my mysql database and got the same error. It's not the fault of script but it's a parsing error.
The correct command is
mysql -h eliuslab.com -u user -pPassWord -D mydatabase -e "INSERT INTO tablename (column) VALUES ('BLABLASTRING')"
Notice there is no need of using quotation marks around the table name and the column name. The quotation marks treat them as string constant rather than a container.

How to be enable to use man command for mysql

I have recently encountered a problem in using the command man and the switch --help in mysql. Whenever I enter the command "man select" or ....
or when I use the "select --help" I recieve this 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 'mysqld --verbose --help' at line 1
The fact is that neither the "man" command nor the "--help" switch work for any other command. My guess is that the man pages are not installed by my system. I use "ubuntu 14.04" and have installe my LAMP STACK via using the "apt-get install" command.
Would you help me fix this issue? I thank you very much in advance.
From the OS command prompt (where you executed the apt-get):
$ man mysql
$ mysql --help
From within the mysql client:
mysql> help select
I think you must see your manual
it's prove man command or not.

Unable to create mysql database dump

I am unable to create mysql database dump. I have tried all the commands in the below question
https://stackoverflow.com/questions/24858436/unable-to-create-mysql-dump-in-mysql-server-5-6-19
But every time I get similar error which asks me to check manual
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 'mysql
dump -u root -pmysqlmysql hospital_management -r "c:\hosp.sql"' at line 1
I am trying these commands in Mysql command line and NOT on Windows command prompt. Also I am trying these commands before entering any database in mysql.
mysql> mysqldump -u root -pmysqlmysql hospital_management > hosp.sql
This was the first command I tried, which did not work
mysqldump is an executable, you should not run it in the MySQL command line.
Try the command
mysqldump -uroot -pmysqlmysql hospital_management > "C:\hosp.sql"
By reading the documentation, I assume that when using -r, the file must already exist.