Resetting your mysql root password

It is quite frequent that an administrator simply forgets his mysql’s root password.

Luckily, it is quiet easy to reset it, here are the steps:

  1. SSH as root to your machine
  2. Turn off the mysqld daemon if running
    • RedHat/Fedora users can do so by executing:  service mysqld stop
  3. Run safe_mysqld by executing:
    • safe_mysqld –skip-grant-tables
      (this will run allow you to connect without a password)
  4. Open a second shell / SSH again and execute:
    • mysql mysql
      (to directly connect and select the mysql database which contains the user authentication data)
  5. On the mysql prompt, execute:
    • update user set password=password(‘newpassword’) where user=’root’;
      where newpassword is your newly chosen password.
  6. That’s it! close everything and start your mysql daemon again:
    • service mysqld start

Add authentication to any php page the easy way

This is useful for anyone who’d like to add a login form to any php page.

Simply, save the following code as access.php, and insert the following snippet on the first line of any php file you want protected.

< ?php include “access.php”; ?> (remove the space before the question mark)

Voila! as easy as 1,2,3. The crentials can be edited in the access.php file, by changing the values of $ADMIN_USER and $ADMIN_PASSWORD.

This useful script requires no database, and no big tweaking to the code on your pages.

PI to 16,777,200 decimals

For the fun of it.

File formats:

PI to 16,777,200 decimals text format 12 MB

PI to 16,777,200 decimals zip format 8 MB

PHP script to import csv data into mysql

This is a simple script that will allow you to import csv data into your database. This comes handy because you can simply edit the appropriate fields, upload it along with the csv file and call it from the web and it will do the rest.

It allows you to specify the delimiter in this csv file, whether it is a coma, a tab etc. It also allows you to chose the line separator, allows you to save the output to a file (known as a data sql dump).

It also permits you to include an empty field at the beginning of each row, which is usually an auto increment integer primary key.

This script is useful mainly if you don’t have phpmyadmin, or you don’t want the hassle of logging in and prefer a few clicks solution, or you simply are a command prompt guy.
Just make sure the table is already created before trying to dump the data.
Kindly post your comments if you got any bug report.

Download file here

How to import a csv file into mysql from the prompt

For the follows out there who do not know how to import coma separated data into mysql from the prompt, here it is:


PATH is the path to the csv file (can be relative to the directory you were in before logging into mysql)
TABLE is the table name that you have already created and whos fields match the csv file fields.
USERNAME is the mysql user that have access to insert data into TABLE
DATABASE is the database containing that table

- login to mysql by typing: mysql -u USERNAME -p DATABASE
The prompt will ask you for the user password, type it.

- Execute the following query:

load data local infile ‘PATH’ into table TABLE fields terminated by ‘,’ lines terminated by ‘\n’;

And voila.

Using iptables in order to share an internet connection

Many users run small networks, be it at home or work. One of the widely used techniques for sharing the internet connection over a small local area network is Microsoft’s ICS (Internet Connection Sharing).

What if the main server is not running windows? Some prefer to opt for linux, and run several services that benefit client computers on this network (such as dns, dhcp, samba, NIS, etc…)

The good news for linux users is that they can benefit from the same functionality of ICS, but using linux iptables.

The following is a sample rule:

/sbin/iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE

Note that you will need to have ip forwarding enabled.

RedHat/Fedora users can execute the following:

echo 1 > /proc/sys/net/ipv4/ip_forward

Now, these rules can be saved in a .sh file, make that shell script executable (chmod +x

Then, make this file execute whenever your system boots. An example would be editing /etc/rc.local and setting the path to that file in there.

This simple iptables rule can be expanded in order to allow certain ports, block others, check protocols for incoming packets on such ports (tcp, udp) , etc.

Advanced rules to come later hopefully.

RPC server unavailable error – Microsoft Internet Connection Sharing (ICS)

Thought of mentioning this as I’ve came across it and noticed many others did too.

If for some reason, whenever you try enabling internet connection sharing (ICS), you get an error saying that the rpc server is unavailable, do the following:

  1. Click on start > run
  2. type services.msc and hit enter
  3. Search for the DHCP Client service, and check its status, it will most probably be stopped.
  4. Double click on this service, change its status to automatic and hit start

that’s it.