Shell error ' @ ' localhost ' (using password:yes) ' root '

Source: Internet
Author: User

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 '

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.