How to Import a SQL file into MySQL on Windows

January 26th, 2011 Fadi El-Eter Posted in MySQL | No Comments »

This is a small code snippet on how to import a SQL file into MySQL on Windows.

- First change to the MySQL Directory
- Now change into the bin directory
- Now run this command:
mysql -u USERNAME -pPASSWORD -h localhost DATABASENAME < c:\\DIR1\\DIR2\\DATA.SQL

I capitalized all the potential variables above (so USERNAME is your username to mysql). Pay attention to the letter “p” before the password. So if your username is testuser, and your password is 12345, and your database is called testdb, then the command will be:

mysql -u testuser -p12345 -h localhost testdb < c:\\DIR1\\DIR2\\DATA.SQL

AddThis Social Bookmark Button

Match Only Word in MySQL

January 3rd, 2011 Fadi El-Eter Posted in MySQL | No Comments »

Sometimes you want to search for a specific word in a MySQL VARCHAR or TEXT field. For example, let’s say you have a field called description in a table called mytable, and you want to search for the word car in the description field. Now if you use this query: SELECT description FROM mytable WHERE description LIKE ‘%car%’; you will get not only the list of descriptions with the word car, but also those with the words care, careless, card, caring, carpenter, etc… If you want only the word car, then you can use the following advanced query (it has regular expressions): SELECT description FROM mytable WHERE description REGEXP ‘[[:<:]](car)[[:>:]]’
The above query will return results with the word car only. Enjoy!

AddThis Social Bookmark Button

How to Load a Tab Delimited CSV Into MySQL on Windows

January 3rd, 2011 Fadi El-Eter Posted in MySQL | No Comments »

I know it’s been so long I have written on this website, but it’s just that I didn’t have any time. Anyway, here’s a little snippet I would like to share with you, how to load a tab delimited CSV into MySQL on Windows. Here’s a step by step guide:

Running MySQL in the Console

- Click on Start, and then type cmd into the textbox where it says “Start Search”. This will open up the black console.
- In the console, go to to the directory where MySQL is installed, for me this is how I go there: cd c:\Software\MySQL (for most people MySQL is installed under the Program Files directory)
- Now change to the bin directory under MySQL: cd bin
- Now type the following command to run MySQL: mysql -u root -p
- You will be prompted for the root password, enter it. (Note, you can also connect using another user by just changing the username in the above step).
- Now you are connected to MySQL.

Selecting the Database

- While you are connected to MySQL, type: use databasename; (where databasename is the name of the database you wish to use).

Loading the Tab Delimited CSV

- Now type the following command:

LOAD DATA LOCAL INFILE ‘c:\\testdata.txt’ INTO TABLE testtable FIELDS TERMINATED BY ‘\t’ LINES TERMINATED BY ‘\n’ (`field1`, `field2`, `field3`);

The table testtable has to exist in the database testdatabase, and has to have the fields “field1″, “field2″, “field3″. Note that in Windows, you add a double backward slash “\\” in your path (so for example, if the csv file is located under c:\myfiles\test.txt, your path will be c:\\myfiles\\test.txt .

- The data now is loaded into the table, where each row in the file becomes a row in the table, and each column in that row fills in a field (for example, the first column of the first row goes to field1, the second column of the first row goes to field2, etc…). When the data is loaded, you will see a similar message:

 Query OK, 69 rows affected, 267 warnings (0.03 sec)
Records: 69  Deleted: 0  Skipped: 0  Warnings: 198

- To show the warnings, just type: show warnings;

That’s it!

If you want to load a comma separated (delimited) file (a CSV), just change the above command that loads the data to:

LOAD DATA LOCAL INFILE ‘c:\\testdata.txt’ INTO TABLE testtable FIELDS TERMINATED BY ‘,’ LINES TERMINATED BY ‘\n’ (`field1`, `field2`, `field3`);

Hope this helps someone!

AddThis Social Bookmark Button

How to Remove the Unwanted p Tag that Wordpress Adds?

September 7th, 2009 Fadi El-Eter Posted in Programming | No Comments »

Wordpress has this annoying habit of adding <p> tags to your post. Most of the times you don’t care, but sometimes it breaks your HTML and makes it non-compliant with W3C. Some have written a component just to handle this, the solution is very simple:

If you want to remove the <p> tag that is added automatically, then all you need to do is to edit the file default-filters.php in the wp-includes directory. Search for this line:

add_filter(’the_content’, ‘wpautop’);

and comment it out by adding // in the start of the line (sorry I have to explain this for non-programmers), so ultimately the line will be:

//add_filter(’the_content’, ‘wpautop’);

Save the file and upload it. There you go, no more of these annoying <p> tags!

This method has one disadvantage, is that when you upgrade Wordpress you have to redo the above, still, it can take you only 1 minute.

AddThis Social Bookmark Button

Eter RSS

July 24th, 2007 Fadi El-Eter Posted in WordPress, Plugins | 25 Comments »

Eter RSS is a WordPress RSS reader. Eter RSS allows WordPress powered sites to seamlessly integrate RSS feeds from other sites.

Specifications

  • Powerful infrastructure: Eter RSS uses lastRSS, known for its stability and its huge userbase.
  • Total control over your RSS feeds: Ability to change the settings for all your feeds and to overwrite these settings on a feed-by-feed basis.
  • Filtering: Ability to filter RSS entries containing unwanted words/sentences.
  • Clean RSS data: No more seeing the & (ampersand) as &.
  • User friendly interface: You will feel in control of your application.
  • Limit the # of RSS entries being displayed: You can set the maximum # of RSS entries to be displayed per RSS feed either globally or on a feed-by-feed basis.
  • Caching: Eter RSS allows you to cache your RSS results for faster access. Caching can happen every 30 minutes or every week, your choice. Caching can be completely turned off.
  • Absolutely free: Free to use, free to modify, it’s a free world!
  • …and more!

Requirements

  • WordPress 2.0+ (older WordPress versions may work)
  • PHP 4+
  • Writable directory anywhere in your website for caching (Eter RSS will attempt to create such directory, but will not complain if it can’t, it just won’t cache).

Installation

  • Extract the zip file and upload the directory Eter RSS to your plugins directory. (usually wp-content/plugins under your home directory).
  • Login as administrator to your WordPress application, and then click on Plugins.
  • Click on Activate next to Eter RSS.
  • Click on Options, and then click on Eter RSS, and follow the instructions.

Quick Start

Eter RSS is quite easy to use. After saving your options here, go to any Post or Page and add the following: <!--eter-rss:url::the_rss_url--> For example, if you want to display Yahoo’s Oddly Enough RSS, just add the following (in code mode): <!--eter-rss:url::http://rss.news.yahoo.com/rss/oddlyenough-->

Advanced

You may want to override the global options set above with specific options for a certain URL:

  • To override the “Maximum Entries Per RSS” option, use the “maximum” keyword followed by the number of maximum entries you want to show, for example <!--eter-rss:url::http://rss.news.yahoo.com/rss/oddlyenough|
    maximum::5-->
    (no line break between the pipe | and maximum) will only display the latest 5 RSS entries from Yahoo’s Oddly Enough.
  • To override the “Filter Entries With Keywords” option, use the “filter” keyword followed by your filter strings, separaterd by commas, for example <!--eter-rss:url::http://rss.news.yahoo.com/rss/oddlyenough|
    filter::curtain,small table,door-->
    will only display the RSS entries not having “curtain”, “small table”, or “door” in either the subject or the description. Note that entries containing “table” but not containing “small table” or “curtain” or “door” will still show. Note that entries containing “SMall taBLE” will not show; comparison is case insensitive.
  • To override the “Show RSS Title” option, use the “title” keyword followed by “yes” or “no”, for example <!--eter-rss:url::http://rss.news.yahoo.com/rss/oddlyenough|
    title::no-->
    will not display the RSS title.
  • To override the “Popup Links in New Window” option, use the “popup” keyword followed by “yes” or “no”, for example <!--eter-rss:url::http://rss.news.yahoo.com/rss/oddlyenough|
    popup::no-->
    . This code will make the RSS links open in the same window.
  • You may mix your options using the pipe (|), for example <!--eter-rss:url::http://rss.news.yahoo.com/rss/oddlyenough|
    maximum::5|popup::no|filter::curtain,small table,door|title::no-->
    will display a maximum of 5 RSS entries where the links open in the same window, where the entries having “curtain”, “small table”, and “door” will not be shown, and where the title of the RSS will not be displayed. Note that there’s no special order when writing your options.

Download Eter RSS Now!

Check the demo at http://www.genoc.net/eter-rss-demo/

I would definitely appreciate your comments.

AddThis Social Bookmark Button