Showing posts with label MySQL. Show all posts
A few days ago I found very useful solution (thanks for Biomathematicus!) for deleting tables from a MySQL schema. I know that it could be quite difficult for some developers (also for me) to manually remove every table from schema without removing this schema itself. So, there is a two-step solution which is going to help you removing a lot of tables from SQL database.
1) List all tables in the MySQL schema :
SELECT CONCAT('drop table ',table_name,'; ')
FROM information_schema.tables
WHERE table_schema = 'yourDatabaseName';
2) Copy result and paste it to query window and execute.
drop table table1;
drop table table2;
Reference : [1] Biomathematicus.blogspot.com Remove all tables from mysql schema
Very useful piece of command line query which will help you to keep an eye on execution time of queries which are performed in your MySQL database. It helps me when I ask myself : 'Hm ... I am wondering if this query is now executed ... '. This question can be sometime annoying, so this is quite helpful adoption of mysqladmin tool.
mysqladmin -u root -p -i 1 processlist -u your username -p you be pleased to give database password -i 1 interval which equals 1 second
Example output :
+----+------+-----------+----+---------+------+-------+------------------+ | Id | User | Host | db | Command | Time | State | Info | +----+------+-----------+----+---------+------+-------+------------------+ | 43 | root | localhost | | Query | 0 | | show processlist | +----+------+-----------+----+---------+------+-------+------------------+
Reference : [1] Mysqladmin Tool Doc
I used to find many times duplicates in my table in MySQL database this time. First of all, I will paste here my table structure below (yes i know that it is difficult to read) :
mysql> describe proxy_parser_statistics;
+-----------------------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------------------+---------+------+-----+---------+----------------+
| ID | int(11) | NO | PRI | NULL | auto_increment |
| file_name | text | NO | | NULL | |
| processing_stamp_date | date | YES | | NULL | |
| processing_stamp_time | time | YES | | NULL | |
| processed_records | int(11) | YES | | NULL | |
+-----------------------+---------+------+-----+---------+----------------+
I just use this query :
SELECT a.id, a.file_name FROM proxy_parser_statistics a INNER JOIN proxy_parser_statistics b ON a.file_name = b.file_name WHERE a.id <> b.id
Results of above query :
+-----+-----------------------------+
| id | file_name |
+-----+-----------------------------+
| 803 | access1211170012.merged.log |
| 804 | access1211170112.merged.log |
| 805 | access1211170212.merged.log |
| 806 | access1211170312.merged.log |
| 807 | access1211170412.merged.log |
| 808 | access1211170512.merged.log |
| 809 | access1211170612.merged.log |
| 810 | access1211170712.merged.log |
| 811 | access1211170812.merged.log |
| 812 | access1211170912.merged.log |
| 813 | access1211171012.merged.log |
| 814 | access1211171112.merged.log |
| 815 | access1211171212.merged.log |
| 816 | access1211171312.merged.log |
| 817 | access1211171412.merged.log |
| 818 | access1211171512.merged.log |
| 819 | access1211171612.merged.log |
| 820 | access1211171712.merged.log |
| 821 | access1211171812.merged.log |
| 822 | access1211171912.merged.log |
| 823 | access1211172012.merged.log |
| 824 | access1211172112.merged.log |
| 825 | access1211172212.merged.log |
| 826 | access1211172312.merged.log |
| 827 | access1211172359.merged.log |
| 727 | access1211170012.merged.log |
| 728 | access1211170112.merged.log |
| 729 | access1211170212.merged.log |
| 730 | access1211170312.merged.log |
| 731 | access1211170412.merged.log |
| 732 | access1211170512.merged.log |
| 733 | access1211170612.merged.log |
| 734 | access1211170712.merged.log |
| 735 | access1211170812.merged.log |
| 736 | access1211170912.merged.log |
| 737 | access1211171012.merged.log |
| 738 | access1211171112.merged.log |
| 739 | access1211171212.merged.log |
| 740 | access1211171312.merged.log |
| 741 | access1211171412.merged.log |
| 742 | access1211171512.merged.log |
| 743 | access1211171612.merged.log |
| 744 | access1211171712.merged.log |
| 745 | access1211171812.merged.log |
| 746 | access1211171912.merged.log |
| 747 | access1211172012.merged.log |
| 748 | access1211172112.merged.log |
| 749 | access1211172212.merged.log |
| 750 | access1211172312.merged.log |
| 751 | access1211172359.merged.log |
+-----+-----------------------------+
Reference :
[1] Table structure Pastebin.com [2] Query result Pastebin.com
