Thursday, January 21, 2016

how to change mysql root password in rhel6 ?

I recently had to reset the MySQL root password due to the fact that initializing it the way I assumed it should did not work. The following procedure will work in CentOS/RHEL/Scientific Linux and Fedora.

After installing MySQL using

# yum install mysql-server
I can run the command

# mysqladmin -u root password 'new-password'
Trying to log in with the following failed

# mysql -u root -p
with the following error

Access denied for user 'root'@'localhost'
Decided to not spend more time as it’s a fresh MySQL installation. And did the following to reset the root password for MySQL.

Resetting the root password

1) Stopped the MySQL service.

# service mysqld stop
2) Started MySQL in safe mode.

# mysqld_safe --skip-grant-tables &
3) Logged in using root.

# mysql -u root
4) Reset the password.

> use mysql;
> update user set password=PASSWORD("mynewpassword") where User='root';
> flush privileges;
> quit
5) Stop MySQL in safe mode.

# service mysqld stop
6) Start MySQL.

# service mysqld start
7) Log in using the new password.


# mysql -u root -p

Friday, January 15, 2016

What is the command for finding the highest memory occupied file in Linux ?



# du –ah / | sort –n –r | head –n 1

Option Explanations :du  – estimate file space usage
a – write counts for all files, not just directories
h – print sizes in human readable format (eg. 1K 234M 2G)
sort – sort lines of text files
n – compare according to string numerical value
r – reverse the result of comparisons
head – output the first part of files

n – number of lines

How to change hostname in Red Hat 6 ?


There are several ways to change the hostname of a machine running Redhat 6.  These also works on CentOS, Fedora and older/other Redhat variants.

First: The "hostname" command.

You can use the hostname command to see the current host name of the system.

# hostname
linux4freshers.com


You can also use the hostname command to change the host name of the machine.

# hostname linuxforfreshers.com

Then issue the hostname command again to see the changes.
# hostname
linuxforfreshers.com

This only makes a temporary or non-persistent change of hostname.

Second: The /etc/sysconfig/network configuration file. (preferred method)

In order for the change to survive a reboot, or to make it persistent, you must change it in the /etc/sysconfig/network-scripts/ifconfig-eth0 file.

Open the file in your favorite editor and change the following line to reflect your desired hostname.

HOSTNAME=linuxforfreshers.com

After making changing to the configuration file you need to restart the network service in order to read that file.

/etc/init.d/network restart
NOTE: Do not do this remotely (via ssh) or you will lose your connection.

If you issue the hostname command now, you will see the hostname has changed.

Third: The /proc/sys/kernel/hostname entry.

Another simple way to change the hostname is to echo the hostname into the /proc/sys/kernel/hostname file.

echo "linuxforfreshers.com" > /proc/sys/kernel/hostname


NOTE: Using the /etc/sysconfig/network file is the preferred method to set the permanent hostname of a system.  Anything in the /proc/sys/kernel/hostname file will be overridden by the /etc/sysconfig/network file during a reboot.