Showing posts with label unix. Show all posts
Showing posts with label unix. Show all posts
Wednesday, July 4, 2012

Reset MySQL root password in Windows and UNIX

1.    Shutdown the MySQL Server –

a.    Use windows services to shut down: Start > run > services.msc  > MySQL > right click and select STOP 




b.    Using mysqladmin by running following command in command prompt:

mysqladmin -u root shutdown (make sure to provide the correct path for mysqladmin if it has not been added in windows path)

2.     Start the MySQL Server in safe mode (anonymous login):

         C:\>start mysqld-nt --skip-grant-tables (A black screen will flicker and here you go)




        In UNIX environment u has to use below command:

              mysqld_safe --skip-grant-tables

3.    Now you open the command line and try to connect to the root user with empty password by running below command:

             C:\>Mysql -uroot

4.    when you logged in u will get a prompt as

             mysql>

5.    Now select the MySQL database:

             use mysql;




6.    Update the root password by running this command:

             mysql> update user set Password=PASSWORD('<new-password>') WHERE User='root';



7.    Shutdown the MySQL Server:  (it is very important to stop the server at this stage since it is running in anonymous mode):

              mysqladmin -u root shutdown

8.    Now start server again and can log in with new password.
Saturday, August 20, 2011

zfs Snapshot Commands Example


As i have already discussed in my previous post zfs filesystem and MySQL about zfs overview and two most important command zpool and zfs. I am going to continue with usage of zfs snapshots. It includes create a pool, Create file system, Taking a snapshot, Renaming Snapshots, Listing all snapshots, restoring from snapshot and Moving the snapshot to other location.

snapshot is a read-only copy of a file system or volume. Snapshots can be created almost instantly, and initially consume no additional disk space within the pool. However, as data within the active dataset changes, the snapshot consumes disk space by continuing to reference the old data and so prevents the space from being freed. Snapshots of volumes cannot be accessed directly, but they can be cloned, backed up, rolled back to.

Creating a Pool:
# zpool create zpool1 c2t0d0

List pool:
# zpool list

Create file system under above create pool:
Once you have a storage pool, you can build file systems on it:

# zfs create zpool1/data # zfs create zpool1/logs
Here we have built “/data” file system on pool zpool1

List all zfs file systems:
# zfs list

Taking a Snapshot:
zfs snapshot < pool name>/<filesystem name>@<snapshot name>
Example:
# zfs snapshot zpool1/data01@Snapshot1

Remove/Destroy a Snapshot:
zfs destroy < pool name>/<filesystem name>@<snapshot name>
Example:
# zfs destroy zpool1/data01@Snapshot1

Rename Snapshots:
You can rename snapshots but they must be renamed within the pool and dataset from which they were created.
zfs rename < pool name>/<filesystem name>@<snapshot name> < pool name>/<filesystem name>@<snapshot name>
Example:
# zfs rename zpool1/data01@Snapshot1 zpool1/data01@Snapshot2

Below snapshot rename operation is not supported because the target pool and file system name are different from the pool and file system where the snapshot was created.

# zfs rename zpool1/data01@Snapshot1 zpool3/data01@Snapshot2

Displaying zfs Snapshots:
zfs list
zfs list -t snapshot

You can also list snapshots that were created for a particular file system:
zfs list -r -t snapshot -o <name>,<creation> <pool>/<home>

Restore/Rolling Back zfs snapshots:
zfs rollback < pool name>/<filesystem name>@<snapshot name>
Example:
# zfs rollback zpool1/data01@Snapshot1

This will restore the entire file system with snapshot.

Restoring individual files:
It is possible to copy individual file from a snapshot by changing into the hidden “.zfs” directory of the pool that has been snapped.

cd /<pool name>/<file system name>
cd .zfs
cp <required file source location> <destination>

Example:
cd /zpool1/data01
cd .zfs
cp <required file source location> <destination>

Moving a  Snapshot to another system:
Wecan move the snapshot to another system and install it there as a usable file system. But at first we need to create a pool to receive the snapshot on the target system.

Step1: Create Pool on another system.
# zpool create -f zpool11 c2t0d0

Step2: Send the snapshot over the network and receive it into the pool using a combination of zfs send/receive command and a netwolrk pipe.
# zfs send zpool1/data01@snapshot1 | ssh <destination host> “usr/sbin/zfs receive zpool11/<myfilesystem>

Here zpool11 is the name of pool on another system which we have created above and myfilesystem is the name of filesystem you wish to put.

Friday, July 1, 2011

GET SIZE OF DIRECTORY (EXCLUDE SUBDIRECTORY) IN UNIX

We all know du command to get the size of a directory. But the problem is when you use "du <directory name>" it will give you the list of all subdirectory including the directory you want with size.

Bt what if i only want the size of directory which i have passed as an argument and not all the subdirectory?

In that senario we can use:

du -sh <directory name>                              

Example 1:

du -h /home/mysql/admin/                             
   1K   /home/mysql/admin/scripts/neel               
   8K   /home/mysql/admin/scripts                    
   1K   /home/mysql/admin/bin-logs/test_instance_4   
   1K   /home/mysql/admin/bin-logs/test_instance_3   
   1K   /home/mysql/admin/bin-logs/orphan            
   1K   /home/mysql/admin/bin-logs/test_instance_1   
   1K   /home/mysql/admin/bin-logs/test_instance_2   
   9K   /home/mysql/admin/bin-logs                   
  20K   /home/mysql/admin                            


In the above example i have have passed "/home/mysql/admin/" as an argument of du and it results all subdirectory with size. (Please note -h switch converts the size into human redable and understandable format i.e KB).

Example 2:

 du -sh /home/mysql/admin/
  20K   /home/mysql/admin

In this example i have used switch "s" ( to show the size of current directory and not the subdirectory) along with "h" (human redable format) and it gave me the size of "/home/mysql/admin"
directory only rather than all subdirectories also.

I hope this will help someone. :)
 
© Copyright 2010-2012 Learn MySQL All Rights Reserved.
Template powered by Blogger.com.