Thursday, July 27, 2017

Fix MySQL InnoDB tablespace exists (corrupt tablespace issue)

Mainly this tablespace error happen when file missing from mysql data folder.
You'll find an orphaned tablename.ibd file without it's normal companion tablename.frm file. If you move that .ibd file to a safe temporary location (just to be safe) that should fix the problem.

Example inside  mysql/data/database_name  folder you'll find this kind of list.
table1.frm
table1.idb
table2.frm
table2.ibd
table3.idb <- problem table, no table3.frm
table4.frm
table4.idb

Here is the solution steps:
  1. backup your database first.
  2. stop mysql engine service
  3. remove the database directory manually from inside mysql/data/database_name.
  4. start mysql engine
  5. create new database with any name different from your corrupted database/ or same name as you want.
  6. Import the backed up database now. 
After restoring your backup and your table will be working fine.

Monday, July 10, 2017

Relative path Vs Absolute path in javascript

The path with reference to root directory is called absolute. The path with reference to current directory is called relative.

Relative Path

 Relative Path <img src="kitten.png"/>   

Absolute Path

 Absolute in all respects: <img src="http://www.foo.com/images/kitten.png">
Example of absolute paths:
  • D:\documents\something.doc
  • E:\music\good_music.mp3
<script>
 var full_path = location.protocol + "//" + window.location.host
</script>


For this page if you inspect the window.location object you will see
hash:       
host:       stackoverflow.com
hostname:   stackoverflow.com
href:       http://stackoverflow.com/questions/8401879/get-absolute-path-in-javascript
pathname:   /questions/8401879/get-absolute-path-in-javascript
port:       
protocol:   http:
search:     

Wednesday, July 5, 2017

MySQL LIMIT on DELETE statement

Suppose you want to delete some old data from a table but need to keep latest data to light weight your database. In that case there are some very simple way to do.

Here one of them. If there is id unique primary column with auto increment, in that table we can delete old id like if you want to delete first 10000 rows  with following command.

"DELETE FROM table_name WHERE id >=10000";
*The conditions in the optional WHERE clause identify which rows to delete. Without WHERE clause, all rows will be deleted.

If the DELETE statement includes an ORDER BY clause, rows are deleted in the order specified by the clause. This is useful primarily in conjunction with LIMIT. For example, the following statement finds rows matching the WHERE clause, sorts them by timestamp_column, and deletes the first (oldest) one:
DELETE FROM somelog WHERE user = 'jcole'
ORDER BY timestamp_column LIMIT 1;
But it's not possible to limit rang like SELECT statement LIMIT 1,500

Total Pageviews