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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
|
04-25-2014, 08:32 AM
|
#1
|
Senior Member
Registered: Jun 2009
Posts: 1,795
Rep:
|
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).
|
|
|
04-25-2014, 09:03 AM
|
#2
|
Member
Registered: Jun 2012
Location: Topeka, KS
Distribution: Mostly AWS
Posts: 71
Rep:
|
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.
|
04-25-2014, 09:10 AM
|
#3
|
Senior Member
Registered: Jun 2009
Posts: 1,795
Original Poster
Rep:
|
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.
|
|
|
04-25-2014, 09:12 AM
|
#4
|
Senior Member
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278
|
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.
|
04-25-2014, 09:19 AM
|
#5
|
Senior Member
Registered: Jun 2009
Posts: 1,795
Original Poster
Rep:
|
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?
|
|
|
04-25-2014, 09:26 AM
|
#6
|
Senior Member
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278
|
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.
|
04-25-2014, 09:30 AM
|
#7
|
Member
Registered: Aug 2012
Distribution: Ubuntu 10.04, CentOS 6.3, Windows 7
Posts: 262
Rep:
|
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.
|
04-25-2014, 09:36 AM
|
#8
|
Senior Member
Registered: Jun 2009
Posts: 1,795
Original Poster
Rep:
|
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.
|
|
|
04-25-2014, 09:46 AM
|
#9
|
Senior Member
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278
|
Something like:
Code:
find / -name ".mysql_history" -exec more {} \;
|
|
1 members found this post helpful.
|
04-25-2014, 09:53 AM
|
#10
|
Member
Registered: Aug 2012
Distribution: Ubuntu 10.04, CentOS 6.3, Windows 7
Posts: 262
Rep:
|
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.
|
04-25-2014, 09:59 AM
|
#11
|
Senior Member
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278
|
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.
|
04-25-2014, 10:00 AM
|
#12
|
Senior Member
Registered: Jun 2009
Posts: 1,795
Original Poster
Rep:
|
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?
|
|
|
04-25-2014, 10:03 AM
|
#13
|
Senior Member
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278
|
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.
|
04-25-2014, 10:55 AM
|
#14
|
Senior Member
Registered: Jun 2009
Posts: 1,795
Original Poster
Rep:
|
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.
|
|
|
04-25-2014, 10:56 AM
|
#15
|
Member
Registered: Aug 2012
Distribution: Ubuntu 10.04, CentOS 6.3, Windows 7
Posts: 262
Rep:
|
Quote:
Originally Posted by rjo98
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.
|
All times are GMT -5. The time now is 03:27 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|