A simple paragraph was written in the shell.
Energy.sh content:
#!/bin/Bashhost=127.0.0.1User=******passwd=******dbname=******TableName=Device_value_300sct007p01_yearmonth=$(Date+%y-%m) sqlstr="INSERT INTO Device_value_300sct007p01_year (id,year,month,device_id,device_value_id,value,type) Select Replace ( UUID (), '-', '), substring (month,1,4), month,device_id,device_value_id,sum (value), type from Device_value_ 300sct007p01_month WHERE month = ${month} GROUP by month,device_id,device_value_id"MySQL-H $host-u$user-p$passwd-D $dbname-E'SELECT * from Device_value_300sct007p01_year'
The simplest query is the error ' @ ' localhost ' (using password:yes) ' root, the username and password are correct
Finally found the reason: more than \ r, the script is written under Windows, due to inconsistent Windows and Linux line breaks cause
Sh-x energy.sh
+ host=$'127.0.0.1\r'+ user=$'******\r'+passwd=$'******\r'+ dbname=$'******\r'+ tablename=$'device_value_300sct007p01_year\r'++Date+%y-%m+ month=$'2015-03\r'+ sqlstr='INSERT INTO Device_value_300sct007p01_year (id,year,month,device_id,device_value_id,value,type) Select Replace ( UUID (),'\"'-'\ '','\ '"'\ ''), SUBSTRING (month,1,4), Month,device_id,devi'GROUP BY month,device_id,device_value_idalue_300sct007p01_month where month = 2015-03+-H $'127.0.0.1\r'$'-uroot\r'$'-pyunho201311\r'-D $'xcloud\r'-E'SELECT * from Device_value_300sct007p01_year'Energy .SH: Line9: -H:command not found+ MySQL $'\ r'ERROR1045(28000): Access denied forUser'Root'@'localhost'(using Password:no)
After each variable is more than \ r, resulting in a bad user name password
Workaround:
Delete \ r in file
Tr-d "\ r" <energy.sh >energy1.sh
Run again
SH energy1.sh
+----------------------------------+------+---------+--------------------+-----------------+-------+------+|ID| Year | Month | device_id | device_value_id | Value | Type |+----------------------------------+------+---------+--------------------+-----------------+-------+------ +| a9be43fcd5cfc6c3e7e07aac6fd20621 | -| -- Geneva|110000001000000031|1|2.00|sum|| a9be43fcd5cfc6c3e7e07aac6fd20622 | -| --Geneva|110000001000000031|1|3.00|sum|| a9be43fcd5cfc6c3e7e07aac6fd20623 | -| --Geneva|110000001000000031|1|4.00|sum|| a9be43fcd5cfc6c3e7e07aac6fd20627 | -| -- on|110000001000000031|1|1.00|sum|+----------------------------------+------+---------+--------------------+-----------------+-------+------+
Shell error ' @ ' localhost ' (using password:yes) ' root '