Mysql Root Password Reseting

Resetting the root password of a MySQL database is trivial if you know the current password if you don’t it is a little tricker. Thankfully it isn’t too difficult to fix, and here we’ll show one possible way of doing so.

If you’ve got access to the root account already, because you know the password, you can change it easily:

steve@steve:~$ mysql –user=root –pass mysql

Enter password:

mysql> update user set Password=PASSWORD(‘new-password-here’) WHERE User=’root’;

Query OK, 2 rows affected (0.04 sec)

Rows matched: 2  Changed: 2  Warnings: 0

mysql> flush privileges;

Query OK, 0 rows affected (0.02 sec)

mysql> exit

ByeHowever if you don’t know the current password this approach will not work – you need to login to run any commands and without the password you’ll not be able to login!

Thankfully there is a simple solution to this problem, we just need to start MySQL with a flag to tell it to ignore any username/password restrictions which might be in place. Once that is done you can successfully update the stored details.

First of all you will need to ensure that your database is stopped:

root@steve:~# /etc/init.d/mysql stopNow you should start up the database in the background, via the mysqld_safe command:

root@steve:~# /usr/bin/mysqld_safe –skip-grant-tables &

[1] 6702

Starting mysqld daemon with databases from /var/lib/mysql

mysqld_safe[6763]: startedHere you can see the new job (number “1”) has started and the server is running with the process ID (PID) of 6702.

Now that the server is running with the –skip-grant-tables flag you can connect to it without a password and complete the job:

root@steve:~$ mysql –user=root mysql

Enter password:

mysql> update user set Password=PASSWORD(‘new-password-here’) WHERE User=’root’;

Query OK, 2 rows affected (0.04 sec)

Rows matched: 2  Changed: 2  Warnings: 0

mysql> flush privileges;

Query OK, 0 rows affected (0.02 sec)

mysql> exit

ByeNow that you’ve done that you just need to stop the server, so that you can go back to running a secure MySQL server with password restrictions in place. First of all bring the server you started into the foreground by typing “fg”, then kill it by pressing “Ctrl+c” afterwards.

This will now allow you to start the server:

root@steve:~# /etc/init.d/mysql start

Starting MySQL database server: mysqld.

Checking for corrupt, not cleanly closed and upgrade needing tables..Now everything should be done and you should have regained access to your MySQL database(s); you should verify this by connecting with your new password:

root@steve:~# mysql –user=root –pass=new-password-here

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 5 to server version: 5.0.24a-Debian_4-log

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

mysql> exit

ByeIf you’d like to automate this process you could start by looking at this simple shell script which will allow you to reset a password with one command.

Published in: on March 20, 2010 at 6:07 am  Comments Off on Mysql Root Password Reseting  

Basic Setting Proftp server and creating ftp account for a user who should login to some other directory other than home directory by default.

Install ProFTPD server

Type the following command as root user:
# yum install proftpd
Start ProFTPD when the system reboot:
# chkconfig --level 3 proftpd on
To start proftpd ftp service, enter:
# service proftpd start
To Stop proftpd ftp server, enter:
# service proftpd stop
To restart proftpd ftp service, enter:
# service proftpd restart
To reload the configuration file, enter:

# service proftpd reload

====================================================

Edit the file /etc/passwd

In the file search for the desired username and edit the default path to the current directory to which he should login

eg;

vel:x:501:502::/home/vel:/bin/bash

change the path of the home directory

vel:x:501:502::/path/to/current/directory:/bin/bash

Then set the necessary permission to the default directory

Either add this user to the group of that directory or change the ownership of the default directory to the new user ownership

===================================================

Edit the /etc/proftp.conf file

Check for the line DefaultRoot and edit or add new line as

DefaultRoot  /path/to/default/directory/  username

eg

DefaultRoot /var/www/html/modules/imageupload/  vel

save the file and restart the proftp

service proftpd restart

Then check from the client software of ftp..


Published in: on March 12, 2010 at 11:06 pm  Comments Off on Basic Setting Proftp server and creating ftp account for a user who should login to some other directory other than home directory by default.  

WordPress Site migration

Codex

Changing The Site URL

// WordPress stores two addresses inside the database. These determine where your blog files are, and where the main index is. On a normal install, these addresses are the same.

There are two occasions where you will need to access the database to alter one or both of these settings:

  1. If you have tried to alter the Blog URL or WordPress URL in Settings, and an error has occurred.
  2. If you have moved to a domain/subdomain with a different name.

BACKUP your database before you begin and store the backup off your site server, like on your hard drive. See: Backing Up Your Database.

Edit wp-config.php

It should be possible to fix the site URL using a new feature –

Add these two lines to your wp-config.php, where “example.com” is the NEW location of your site.

define('WP_HOME','http://example.com');
define('WP_SITEURL','http://example.com');

This is not necessarily the best fix, it’s just hardcoding the values into the site itself. You won’t be able to edit them on the General settings page anymore when using this method.

Thanks filosofo for the fix, implemented in 2.2.

Edit functions.php

If you have access to the site via FTP, then this method will help you quickly get a site back up and running, if you changed those values incorrectly.

1. FTP to the site, and get a copy of the active theme’s functions.php file. You’re going to edit it in a simple text editor (like notepad) and upload it back to the site.

2. Add these two lines to the file, immediately after the initial “<?php” line.

update_option('siteurl','http://example.com/blog');
update_option('home','http://example.com/blog');

Use your own URL instead of example.com, obviously.

3. Upload the file back to your site, in the same location. FileZilla offers a handy “edit file” function to do all of the above rapidly, if you can use that, do so.

4. Load the login or admin page a couple of times. The site should come back up.

5. Repeat the above steps, but remove those lines. IMPORTANT: Do NOT leave those lines in there. Remove them immediately after the site is up and running again.

If there is no functions.php file in the theme: Create a new text file called “functions.php”. Edit it with notepad, and add this text to it, using your own URL instead of example.com:

<?php
update_option('siteurl','http://example.com/blog');
update_option('home','http://example.com/blog');

Upload that to your theme directory, then proceed as stated above. Remove the file afterwards.

Relocate method

WordPress supports an automatic relocation method that will figure out and update those values for you automatically. This method is intended to be a quick assist to getting a site working when relocating a site from one server to another.

To use it:

1. Edit the wp-config.php file.

2. After the “define” statements, add this new one:

define('RELOCATE',true);

3. Go to the wp-login.php page in a web browser.

4. Login as per normal.

When the RELOCATE flag is set to true, the siteurl (NOT the home setting) will be automatically updated to whatever path you are using to access the login screen. This will get the admin section up and running on the new URL, but it will not correct any other part of the setup. Those you will still need to alter manually.

You should remove the additional line after the site is up and running. Do NOT leave it enabled.

Changing the URL directly in the database

If you know how to access phpMyAdmin on your host, then you can edit these values directly to get you up and running again.

  1. Backup your database and save the copy off-site.
  2. Login to phpMyAdmin.
  3. Click the link to your Databases.
  4. A list of your databases will appear. Choose the one that is your WordPress database.
  5. All the tables in your database will appear on the screen.
  6. From the list, look for wp_options. Note: The table prefix of wp_ may be different if you changed it when installing.
  7. Click on the small icon indicated as Browse.
  8. A screen will open with a list of the fields within the wp_options table.
  9. Under the field option_name, scroll down and look for siteurl.
  10. Click the Edit Field icon which usually is found at the far left at the beginning of the row.
  11. The Edit Field window will appear.
  12. In the input box for option_value, carefully change the URL information to the new address.
  13. Verify this is correct and click Go to save the information.
  14. You should be returned to your wp-options table.
  15. Look for the home field in the table and click Edit Field. Note There are several pages of tables inside wp_options. Look for the > symbol to page through them.
  16. In the input box for option_value, carefully change the URL information to the new address.
  17. Verify this is correct and click Go to save the information.
  18. Delete the folder wp-content/cache (this is a new folder added with WordPress 2.0).
  19. That is it.

Domain Name Change

BE VERY CAREFUL WITH THIS.

BACKUP YOUR DATABASE FIRST: Backing Up Your Database.

The following is irreversible. There is no “undo” or “undelete” button. This is permanent. Be warned that it can do harm.

When moving the domain, you will need to restore the database. You then need to upload your files to their new location.

At this point, your blog will NOT work.

  1. Database
    1. Follow the guide above to alter the information in the database.
  2. Database Entries
    1. Log into phpMyAdmin.
    2. Backup your database and save the copy off-site.
    3. Login to phpMyAdmin.
    4. Click the link to your Databases.
    5. A list of your databases will appear. Choose the one that is your WordPress database.
    6. Look for the name of the table within your database used to hold your post information. Usually it is called wp_posts, but it may have been changed. Write it down.
    7. Clicking the Browse icon or link, open the wp_posts table.
    8. Look for the field that holds your post “guid”. It is usually called guid, but it may have been changed. Write it down.
    9. Click the tab at the top for SQL.
    10. Using the information you wrote down from above and the old and new URL addresses you wish to update or search and replace within your database, type in the following (CAREFULLY):
UPDATE wp_posts SET guid = REPLACE (
guid,
'http://exampleoldsiteurl.com',
'http://examplenewsiteurl.com');
    1. Make sure that the names of wp-posts and post_content match the tables and fields within your database. Change them if not.
    2. Ensure that the ONLY content you want to change are within the little single ‘quotes’ . Make sure EVERYTHING is spelled right and that you are sure this is correct.
    3. Review everything within the SQL input box again. Make sure it is correct. There are no second changes when you take the next action. The change is permanent.
    4. When you are sure, click Go.
    5. At the top of the screen will be generated a list of how many of the tables and fields have been changed.

Table Prefixes

Like many WordPress administrators, you may be running several of your WordPress domains off of one installation using various wp-config.php hacks. Many of these hacks involve dynamically setting table prefixes, and if you do end up altering your table prefix, you must update several entries within the prefix_usermeta table as well.

As in the above section, remember that SQL changes are permanent and so you should back up your database first:

UPDATE `newprefix_usermeta` SET `meta_key` = REPLACE( `meta_key` , 'oldprefix_', 'newprefix_' );

Changing Template Files

In your WordPress Theme, open each template file and search for any manually entered references to your old domain name and replace it with the new one. Look for specific hand coded links you may have entered on the various template files such as the sidebar.php and footer.php.

WordPress uses a template tag called bloginfo() to automatically generate your site address from information entered in your Administration > Settings > General panel. The tag in your template files will not have to be modified.

Changing the Config file

You will need to update your WordPress configuration file if your database has moved or changed in certain ways.

  1. You will only need to modify the config file if:
    1. your database has moved to another server and is not running on your localhost
    2. you have renamed your database
    3. you have changed the database user name
  2. “‘Make a backup copy of your wp-config.php file.'”
  3. Open the wp-config.php file in a text editor.
  4. Review its contents. In particular, you are looking for the database host entry.
  5. Save the file.

At this point, your WordPress blog should be working.

Verify the Profile

  1. In your Administration Panels go to Settings > General . Here you will verify that the changes you made in Changing the URL above, are correct.
  2. Verify that the reference in your WordPress URL contains the new address.
  3. Verify that the reference in your “Blog URL” contains the new address.
  4. If you have made changes, click Save Changes.

Changing the .htaccess file

After changing the information in your Administration > Settings > General panel, you will need to update your .htaccess file if you are using Permalinks or any rewrites or redirects.

  1. Make a backup copy of your .htaccess file. This is not a recommendation but a requirement.
  2. Open the .htaccess file in a text editor.
  3. Review its contents, looking for any custom rewrites or redirects you entered. Copy these to another text file for safe keeping.
  4. Close the file.
  5. Follow the instructions on the Permalinks SubPanel for updating your Permalinks to the .htaccess file.
  6. Open the new .htaccess file and check to see if your custom rewrites and redirects are still there. If not, copy them from the saved file and paste them into the new .htaccess file.
  7. Make any changes necessary in those custom rewrites and redirects to reflect the new site address.
  8. Save the file.
  9. Test those redirects to ensure they are working.

If you make a mistake, you can Restoring Your Database From Backup from your backup and try this again. So make sure it is right the first time.

Additional Information

Much of this information was taken from Podz’ WordPress Guides where this topic is also discussed.

Some other things you should consider a FULL Search & Replace in your SQL database.

  1. Images link: image links are stored in “post_content” in the wp_posts table. You can use the similar code above to update image links.
  2. wp_options: Besides the “siteurl” and “home” items mentioned above, there are other option_value which also need revision, such as “upload path”, and some plugin items (depends on what you’ve installed, such as widgets, stats, DMSGuestbook, sitemap, etc.)
  3. Do a FULL database search for any items left. MAKE SURE you know what you are changing. and go through each item for possible improper replacement.
Published in: on March 10, 2010 at 10:57 pm  Comments Off on WordPress Site migration  

How to find a particular word in a file or files in a directory

login to that directory where the word from the files to be searched and type the bellow command ,

example:

 grep -r -w “prioritycalendars.com.” *

Word name = prioritycalendars.com.

*=whole sub directory and files under the main directory

Cheers

siva.d

Published in: on March 10, 2010 at 10:35 pm  Comments Off on How to find a particular word in a file or files in a directory