Table got dropped from phpmyadmin - php

I have a PHP application which is on a production server and it`s meant to register users to some services. It has two forms which registers a user in a different table from my database.
Problem is that today one of the tables disappeared and I was able to restore it from a backup. But this dose`t get rid of the problem.
How do I investigate this in order to determine how that table got lost and most likely dropped by some bot or something.
How would you proceed in a situation like this?

There are two ways:
Have a working backup of the system, and restore the files from it.
An undelete tool might help, if you deleted the db very recently (and ideally, if you unplugged the computer right afterward).
As for doing it with MySQL, though...on all systems i'm aware of, no. MySQL tables are files in the server's data directory, and dropping a table deletes those files. Once they're gone, they're gone, and only the methods above can get them back. A database is a directory of those files, and dropping it deletes the whole directory.
Check this free software
http://www.majorgeeks.com/Restoration_d4474.html
More information here - http://emaillenin.blogspot.com/2010/11/recover-accidentally-deleted-mysql.html

If your tables got dropped, find out what mysql users have privileges to drop a table (there shouldn't be many) and what services log in with that user credentials.
Maybe you have a web form with a php backend that doesn't clean up (escape) input, so you were maybe open to sql injection.
In that case, you could check you webserver access log.

Related

Migrating Wordpress servers, same domain.. Few questions

I'm helping a friend migrate her wordpress server to GoDaddy, and I think I may have bitten off more than I can chew... I've never migrated a wordpress before. This page here is the Wordpress wiki for moving Wordpress when your domain isn't changing. It doesn't seem to complex, but I'm terrified of accidentally ruining this website and I don't understand a couple of things on the wiki.
The Wiki says
If database and URL remains the same, you can move by just copying your files and database.
Does this mean that I can just log in to her server from Filezilla and copy all of the files on the server? What does database mean, is that something separate from the files on the server?
If database name or user changes, edit wp-config.php to have the correct values.
This sort of goes with my first question.. What initiates a database name or user change?
Apologies for my ignorance, but after an hour or so of searching around for these answers I'm left just as confused.
Last but not least, is there anything else I should be aware of when migrating a wordpress? I'm a little nervous..
You are going to need to migrate you instalation in two parts.
Part 1 you already eluded to. You will need to copy the files from one server to another. I am guessing you know how to do this so I will not dive any deeper into it. If you do need more explanation, please let me know and I will edit the question.
Part 2 is what you mentioned but said you did not understand. Copying the database of wp install. Wordpress runs off of PHP and MySQL. The "files" part in part 1 is the PHP files (along with some html and css). You need to log into his MySQL server and do an export of his database. You should be able to export the database (How to export mysql database to another computer?) and import it into his new server on GoDaddy. (Error importing SQL dump into MySQL: Unknown database / Can't create database).
Just take things slow, follow the guides that I have linked and do not delete anything from the first server until everything is working on the second. Please let me know if you do not understand anything.
if you don't feel confortable with database exports and imports, try using plugins like:
http://wordpress.org/plugins/duplicator/
or
http://wordpress.org/plugins/wordpress-move/
Check his docs for info.
Luck!
• A database is literally a data base. It's where websites (and other applications) store their data eg. For Wordpress, it would be data such as posts, user information etc.
If you are using a cPanel setup then you would need to get access to it and navigate to phpMyAdmin which is the GUI for managing a database.
Now I'm not sure what type of setup you're using but that should be a start.
• A database has a connection server address (usually localhost), a database name, username and password. These are setup at the time of setting up a database.
When migrating servers, you would need to update those details in the wp-config.php file (I think around line 19 or so).
• The annoying part about migrating Wordpress to another server is the domain change as you have to update the old domain with the new domain throughout the database. However since you're not changing domain names, it should be a smooth ride as long as the new server supports PHP and has a database.

MySQL Databases with Ghost Data?

I wrote a PHP tool a while back that allows us to automatically setup free MySQL Databases for our customers in an internal standalone installation. It works fine but we recently were forced to migrate the databases due to hardware failure.
After doing so, the existing MySQL databases seem to have some type of ghost data in them. We cannot see these tables in PHPMyAdmin but it is detected by our customer's plugins and some of our own tools.
I have never heard of MySQL Ghost Data like this before and was wondering if anyone has any idea where this comes from or how to fix it?
Ghost Data.. interesting!
I am not sure, but I think you are talking about INFORMATION_SCHEMA, which provide access to database metadata. Check This
And, wherever you migrate to, most of the databases have these metadata-tables.
Ex: SQL SERVER has sysobjects or sysusers tables and many more...

Lock write to database during maintenance wordpress mysql

I'm doing a manual WordPress update.
I backed up the database to a .sql file.
Is there any way to prevent write to database temporarily while still allowing read to the whole MySQL database?
This is to ensure
The backed up database is up to date
Users are still able to browse contents on my website without disruption (I will put up a maintenance notice that your posts will not be saved etc.)
Update
The upgrading activity is only used as an example here.
I'm planning to make some changes directly to the database as well and it will take a while.
I'm sure I have seen websites (famous one) showing that they were under maintenance and that my comments/ posts would not be recorded (no write) but I was still able to browse their websites (read is ok).
I thought it was quite a reasonable need, was it not?
I'm sure there must be a way to
Serve the caches of webpages (server-side) to users while not connecting the the database at all in up to a couple of hours (logging in/ registration will not available to users but that's ok)? How do you think I can achieve that then?
To lock out any visitors from posting comments and such, you can go into phpmyadmin, find the wordpress user account (DB_USER as defined in wp-config.php) and revoke its insert, edit and update privileges. But this will probably not degrade gracefully into user friendly error messages when they still try anyways ignoring your messages. And if you are doing an update through php script in the way the wordpress installs itself it may still need these privledges to make any necessary modifications like adding options to the options table.
What version are you upgrading from and to? I know the install took me all of 30 seconds, and I can't imagine there would be a huge change in database between updates. But then again WP can be highly customized and I don't know the extent your site deviates from the standard install.
Sorry I'm about to go to sleep so I won't go into depth but one way that works for sure is if you have two MySQL users, 1 for your website to read/write from and another to do your maintenance. Your first user, you can change his privileges temporarily to read only and that should work.

Retrieve a deleted database in PHPMyAdmin

I accidently deleted the whole database when I should just delete one table in PHPMyAdmin. Is there a way of retrieving the database?
There are two ways:
Have a working backup of the system, and restore the files from it.
An undelete tool might help, if you deleted the db very recently (and ideally, if you unplugged the computer right afterward).
As for doing it with MySQL, though...on all systems i'm aware of, no. MySQL tables are files in the server's data directory, and dropping a table deletes those files. Once they're gone, they're gone, and only the methods above can get them back. A database is a directory of those files, and dropping it deletes the whole directory.
Same thing here :-(
I closed xampp (V3.2.1) found the xampp\mysql\ folder, right-clicked and selected Restore previous version, select recent restore. When this finished I opened xampp and the missing database was back with the information dated as per the restore date. Not ideal but better than no database :-)
Same thing happened with me, found a easy solution. First make a command line access to the database using the mysql.exe file present in xampp/php/bin folder. Delete the phpmyadmin database. Then, just import the create_tables.sql file to the phpmyadmin database. This solved my problem.
Let me know if you face any problem using this.
thanks.
You can retrieve a accidentally deleted database via a file restoration software. Check this free software
http://www.majorgeeks.com/Restoration_d4474.html
More information here -
http://emaillenin.blogspot.com/2010/11/recover-accidentally-deleted-mysql.html

PHP/mysql application creation process

I am trying to figure out how one would start the setup of a small CMS.
I have the groundwork built, but the step of creating the database tables in mysql, should this all be done at once in a install.php file? Is there a preferred method for creating many tables at once, even if I don't need to insert data into them at this time?
You can
Import the schema file to your database prior to deploying the application
You can have a script that creates the schema
You can have a script that makes any changes to the current schema (for upgrades)
For a small CMS, I'd just keep the SQL in a schema file and import it when I need it.
You could also do a database copy from your dev -> live system. So you make the changes in the dev database as you need them and then push them to the live database. Something like SQLCompare for SQL Server works well.
Wordpress does the install.php route, where you have to enter your credentials and such for the target database and it then pushes the changes to it.
If you're going to be distributing your application for 3rd parties to install on their own servers, a very common approach is to provide (as you said) a simple install.php file. If your application is more complicated, often times an installation directory will come packaged. The user installing the application opens this in a browser, where your script typically does a few things:
Check PHP installation - verify (using function_exists()) all the required functions (and thus libraries) are installed and available. Alert the user of anything missing.
Allow the user to enter their configuration parameters - application specific settings required. Typically database hostname, username & password.
Test database connection - if successful, load initial tables. Commonly you keep your base schema file stored as a SQL file, so the application pushes this through the native mysql client, or issues the individual SQL commands directly.

Categories