LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-14-2011, 07:08 AM   #1
papa2ae
LQ Newbie
 
Registered: Jun 2011
Posts: 10

Rep: Reputation: Disabled
Bash and mysql issue


I have tried many different ways to interact with the mysql to reset the root mysql pass.

This is what I got to right now ...

Code:
#!/bin/sh

newpass=$1

service mysqld stop

mysqld_safe --skip-grant-tables --skip-networking &

echo "use mysql;" >> /tmp/mysql_pass_reset.txt
echo "update user set password=PASSWORD(\"$newpass\") where User=\"root\";" >> /tmp/mysql_pass_reset.txt
echo "FLUSH PRIVILEGES;" >> /tmp/mysql_pass_reset.txt

mysql -h localhost -uroot < /tmp/mysql_pass_reset.txt


service mysqld stop


service mysqld start


rm -rf /tmp/mysql_pass_reset.txt
If i run the commands manually, it works - but automatically with bash it doesn't.

This however, tested and all, doesn't seem to work. It doesn't really update the pass with the new one. And any password will work and drop the user into mysql console aswell.

Am I missing something? :P

ty
 
Old 06-14-2011, 07:15 AM   #2
ssrameez
Member
 
Registered: Oct 2006
Location: bangalore
Distribution: Fedora, Ubuntu, Debian, Redhat
Posts: 82

Rep: Reputation: 6
i am not an expert in mysql.
But will the following help.

mysql --host=localhost --user=root --password=password < /tmp/mysql_pass_reset.txt
 
Old 06-14-2011, 07:17 AM   #3
papa2ae
LQ Newbie
 
Registered: Jun 2011
Posts: 10

Original Poster
Rep: Reputation: Disabled
Well ...

because we start mysql as mysqld_safe and we skip networking and grant tables. You can login without password so you can reset the pass.

So

mysql -h localhost -uroot < /tmp/mysql_pass_reset.txt

Will work ...

but for some reason, in the bash code, it doesn't work - but it works manually.
 
Old 06-14-2011, 07:19 AM   #4
ssrameez
Member
 
Registered: Oct 2006
Location: bangalore
Distribution: Fedora, Ubuntu, Debian, Redhat
Posts: 82

Rep: Reputation: 6
Another troubleshooting thought..

`mysql -h localhost -uroot < /tmp/mysql_pass_reset.txt`
try this in the script.
 
Old 06-14-2011, 07:22 AM   #5
ssrameez
Member
 
Registered: Oct 2006
Location: bangalore
Distribution: Fedora, Ubuntu, Debian, Redhat
Posts: 82

Rep: Reputation: 6
also have look at "http://www.linuxquestions.org/questions/linux-server-73/sql-commands-inside-bash-script-879004/"
 
Old 06-14-2011, 07:28 AM   #6
papa2ae
LQ Newbie
 
Registered: Jun 2011
Posts: 10

Original Poster
Rep: Reputation: Disabled
Quote:
`mysql -h localhost -uroot < /tmp/mysql_pass_reset.txt`

However, when i run the code now and debugged

I get when inserting /tmp/mysql_pass_reset.txt into the mysql

ERROR 2002 ; which is cant connect to local mysql server through socket ... /var/lib/mysql/mysql.sock

and apparently the mysqld_safe doesnt seem to work either :S

Any help is appreciated <3

ty
 
Old 06-14-2011, 05:39 PM   #7
papa2ae
LQ Newbie
 
Registered: Jun 2011
Posts: 10

Original Poster
Rep: Reputation: Disabled
Any other ideas?

:/

ty
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Apache2, PHP5, or MYSQL issue: Unable to jump to row 0 on MySQL ..... MTAS Linux - Server 5 03-26-2010 10:13 AM
Can MySQL log on via SSH/bash? mysql:x:27:101:MySQL Server:/var/lib/mysql:/bin/bash Ujjain Linux - Newbie 2 04-24-2009 03:21 PM
Bash - Mysql chriskippi Programming 1 11-16-2008 05:59 PM
Buzilla issue: "Can't connect to local MySQL server through socket '/tmp/mysql.sock'" vitopn Linux - General 3 05-21-2007 11:13 AM
Bash + Mysql Help xianzai Programming 4 10-28-2004 09:15 AM


All times are GMT -5. The time now is 12:44 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration