Connect to MySQL trough command line without need root password

Posted by ReynierPM on Server Fault See other posts from Server Fault or by ReynierPM
Published on 2012-06-15T19:42:10Z Indexed on 2012/06/15 21:18 UTC
Read the original article Hit count: 176

Filed under:
|
|
|
|

I'm building a Bash script for some tasks. One of those tasks is create a MySQL DB from within the same bash script. What I'm doing right now is creating two vars: one for store user name and the other for store password. This is the relevant part of my script:

MYSQL_USER=root
MYSQL_PASS=mypass_goes_here

touch /tmp/$PROY.sql && echo "CREATE DATABASE $DB_NAME;" > /tmp/script.sql
mysql --user=$MYSQL_USER --password="$MYSQL_PASS" < /tmp/script.sql
rm -rf /tmp/script.sql

But always get a error saying access denied for user root with NO PASSWORD, what I'm doing wrong? I need to do the same for PostgreSQL, any help?

Regards and thanks in advance

© Server Fault or respective owner

Related posts about linux

Related posts about mysql