LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-25-2014, 08:32 AM   #1
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Rep: Reputation: 49
mysql abandoned, need to figure it out in a hurry


Let me first preface this by saying I've used Windows MS SQL in the past, but never MySQL, and never any db software in RHEL. But here's my situation.

Our Linux/DB guy has ditched us, so now we're between a rock and a hard place. We have some software where supposedly we need to "clear out some tables" to reset it to blank so it can be used for it's next cycle. Only problem is, I have no idea where to start.

As root, I su'd to that guy's account on the server it's running on. I see in his history he has the following line
mysql WhatImGuessingIsTheDatabaseName -pWhatImGuessingIsTheDatabasePassword

I'm afraid to run that command because I'm not clear on what to do. Also, if that allows me to get into MySQL, does it have any "history" type command where I could possible determine which tables and how he has cleared them out in the past?

Or is there something I can install on my Windows machine which could help with this? (and not let me mess this database up).
 
Old 04-25-2014, 09:03 AM   #2
vmccord
Member
 
Registered: Jun 2012
Location: Topeka, KS
Distribution: Mostly AWS
Posts: 71
Blog Entries: 31

Rep: Reputation: Disabled
1. Don't panic. (Large friendly letters.
2. mysql WhatImGuessingIsTheDatabaseName -pWhatImGuessingIsTheDatabasePassword
You are right in your guessing. It opens up the SQL interface for mysql for that particular database. And once you have, you may be able to see the history. The up arrow will display the same way that it does in the bash command line interface.
3. sql is sql. So, "Show tables;" Will show you the tables in that particular database.
4. There is gui interface available, but that's all I know about it. Think of this as an excellent time to learn mysql.

Last edited by vmccord; 04-25-2014 at 09:04 AM.
 
1 members found this post helpful.
Old 04-25-2014, 09:10 AM   #3
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Original Poster
Rep: Reputation: 49
1. haha, thanks, I needed that
2. Knowing MySQL CLI has the up arrow history makes me feel a LOT better. Now I just have to get the nerve to actually run that command.
3. For my prior experience with MS SQL, I always had a GUI for about 95% of the stuff, and only had to do command line when things got ugly.
4. Yeah, I wouldn't mind sticking with the command line. Maybe I can find a cheat sheet of frequent commands. Heck, at this point, I wouldn't even know how to exit out of MySQL CLI haha.

Also, as I'm digging through this persons notes/files, I did find one that just had three random lines in it, all saying "truncate NameOfSomething;". Those sound very database-ish to me, and the names after truncate logically sound like what could be table names in a database.

And probably most importantly what I need to figure out how to do, is how I would backup and restore that WhatImGuessingIsTheDatabaseName.
 
Old 04-25-2014, 09:12 AM   #4
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
to view his history you can open the file .mysql_history in his home directory... assuming root:

Code:
less /root/.mysql_history
this part is more tricky. I am only generalizing here, but youll want to find lines like this:

Code:
use somedatabasename;
delete from sometablename
That will give you a clue of what he did and where he did it. Luckily mysql saves all command history unless you disable it.
 
1 members found this post helpful.
Old 04-25-2014, 09:19 AM   #5
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Original Poster
Rep: Reputation: 49
Looking at root's .MySQL_history this is all that's in it:
show master status;
SHOW MASTER STATUS;
show databases
;
SHOW MASTER STATUS;
show databases
;
SHOW MASTER STATUS;
show master status;

Looking under his account, all I get is this
show databases;
FLUSH TABLES WITH READ LOCK;

Maybe he used yet another account on the server?
 
Old 04-25-2014, 09:26 AM   #6
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
Correct. You'll want to check all the .mysql_history files then.

Anyone happen to know where the history goes if you log in through the client remotely? I don't think it keeps history in that case.
 
1 members found this post helpful.
Old 04-25-2014, 09:30 AM   #7
YankeePride13
Member
 
Registered: Aug 2012
Distribution: Ubuntu 10.04, CentOS 6.3, Windows 7
Posts: 262

Rep: Reputation: 55
Depending on how you have your ACLs set up, you might be able to use this MySQL workbench on a windows machine to give you a GUI look at the database:

http://www.mysql.com/products/workbench/
 
1 members found this post helpful.
Old 04-25-2014, 09:36 AM   #8
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Original Poster
Rep: Reputation: 49
Is there a slick way to more all the users on my server's .MySQL_history files? or do I have to manually look for them all?

Thanks for the gui suggestion Yankee.
 
Old 04-25-2014, 09:46 AM   #9
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
Something like:

Code:
find / -name ".mysql_history" -exec more {} \;
 
1 members found this post helpful.
Old 04-25-2014, 09:53 AM   #10
YankeePride13
Member
 
Registered: Aug 2012
Distribution: Ubuntu 10.04, CentOS 6.3, Windows 7
Posts: 262

Rep: Reputation: 55
Also, make sure you back up the database before you do anything. The command is:
Code:
mysqldump --password='$password' $database [$table] > /some/path/to/backup/backup.sql
 
1 members found this post helpful.
Old 04-25-2014, 09:59 AM   #11
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
Be wary of making a backup of a production database!

Keep in mind that a backup can be huge, so check the size of your drive before you do this.

Also, you might have to wait until later in the day if this is a production server so you don't affect services by locking tables or anything, especially if you are using isam tables.
 
1 members found this post helpful.
Old 04-25-2014, 10:00 AM   #12
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Original Poster
Rep: Reputation: 49
That command only came up with the same stuff
show databases;
FLUSH TABLES WITH READ LOCK;
show master status;
SHOW MASTER STATUS;
show databases
;
SHOW MASTER STATUS;
show databases
;
SHOW MASTER STATUS;
show master status;

thanks for the backup command too Yankee

---------- Post added 04-25-14 at 11:01 AM ----------

Yeah, i'd try a backup during the off hours. but how can I tell how big the database is anyway?
 
Old 04-25-2014, 10:03 AM   #13
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
I use this to get database sizes:

Code:
SELECT table_schema AS "Data Base Name", 
sum( data_length + index_length ) / 1024 / 1024 AS "Data Base Size in MB" 
FROM information_schema.TABLES GROUP BY table_schema ;
 
3 members found this post helpful.
Old 04-25-2014, 10:55 AM   #14
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Original Poster
Rep: Reputation: 49
ok, thanks. after I make time to make a backup, and get brave enough to actually log in to MySQL, I will let you know.

or I wonder if there's a way I can back it up then restore it to my machine to test with. that might be good.

Thanks for all the help everyone, I'm feeling a lot better than I was when I originally posted.
 
Old 04-25-2014, 10:56 AM   #15
YankeePride13
Member
 
Registered: Aug 2012
Distribution: Ubuntu 10.04, CentOS 6.3, Windows 7
Posts: 262

Rep: Reputation: 55
Quote:
Originally Posted by rjo98 View Post
or I wonder if there's a way I can back it up then restore it to my machine to test with. that might be good.
You sure could. Just install MySQL locally on your machine or in a VM. But if the data is sensative, be sure to put it in a safe place and keep your system updated.
 
1 members found this post helpful.
  


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
did anybody figure out mysql.sock error? needforspeed Linux - Software 7 10-31-2018 04:57 PM
can't figure out the sql for a corss table mysql view mjh Programming 1 02-17-2008 12:02 PM
No hurry! JormaH LinuxQuestions.org Member Intro 3 08-31-2007 01:02 PM
Need some help in a hurry rodneybeighle Linux - Software 2 09-29-2005 08:10 AM
Hurry ;) Profanity Linux - Software 11 07-25-2003 04:30 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:27 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
Open Source Consulting | Domain Registration