Search Posts on Binpipe Blog

Handy Mysql Commands

 These are a few handy Mysql commands I have always used. You will find them useful particularly if you are a newbie. Please add more of them in the comments so that it becomes a really useful thread.
 
Please note that below when you see # it means from the Linux/Unix shell. When you see mysql> it means from a MySQL prompt after logging into MySQL.


  • To login (from unix shell) use -h only if needed.

# [mysql dir]/bin/mysql -h hostname -u root -p
  • Create a database on the sql server.

mysql> create database [databasename];
  • List all databases on the sql server.

mysql> show databases;
  • Switch to a database.

mysql> use [db name];
  • To see all the tables in the db.

mysql> show tables;
  • To see database's field formats.

mysql> describe [table name];
  • To delete a db.

mysql> drop database [database name];
  • To delete a table.

mysql> drop table [table name];
  • Show all data in a table.

mysql> SELECT * FROM [table name];
  • Returns the columns and column information pertaining to the designated table.

mysql> show columns from [table name];
  • Show certain selected rows with the value "whatever".

mysql> SELECT * FROM [table name] WHERE [field name] = "whatever";
  • Show all records containing the name "Bob" AND the phone number '3444444'.

mysql> SELECT * FROM [table name] WHERE name = "Bob" AND phone_number = '3444444';
  • Show all records not containing the name "Bob" AND the phone number '3444444' order by the phone_number field.

mysql> SELECT * FROM [table name] WHERE name != "Bob" AND phone_number = '3444444' order by phone_number;
  • Show all records starting with the letters 'bob' AND the phone number '3444444'.

mysql> SELECT * FROM [table name] WHERE name like "Bob%" AND phone_number = '3444444';
  • Show all records starting with the letters 'bob' AND the phone number '3444444' limit to records 1 through 5.

mysql> SELECT * FROM [table name] WHERE name like "Bob%" AND phone_number = '3444444' limit 1,5;
  • Use a regular expression to find records. Use "REGEXP BINARY" to force case-sensitivity. This finds any record beginning with a.

mysql> SELECT * FROM [table name] WHERE rec RLIKE "^a";
  • Show unique records.

mysql> SELECT DISTINCT [column name] FROM [table name];
  • Show selected records sorted in an ascending (asc) or descending (desc).

mysql> SELECT [col1],[col2] FROM [table name] ORDER BY [col2] DESC;
  • Return number of rows.

mysql> SELECT COUNT(*) FROM [table name];
  • Sum column.

mysql> SELECT SUM(*) FROM [table name];
  • Join tables on common columns.

mysql> select lookup.illustrationid, lookup.personid,person.birthday from lookup left join person on lookup.personid=person.personid=statement to join birthday in person table with primary illustration id;
  • Creating a new user. Login as root. Switch to the MySQL db. Make the user. Update privs.

# mysql -u root -p
mysql> use mysql;
mysql> INSERT INTO user (Host,User,Password) VALUES('%','username',PASSWORD('password'));
mysql> flush privileges;
  • Change a users password from unix shell.

# [mysql dir]/bin/mysqladmin -u username -h hostname.blah.org -p password 'new-password'
  • Change a users password from MySQL prompt. Login as root. Set the password. Update privs.

# mysql -u root -p
mysql> SET PASSWORD FOR 'user'@'hostname' = PASSWORD('passwordhere');
mysql> flush privileges;
  • Recover a MySQL root password. Stop the MySQL server process. Start again with no grant tables. Login to MySQL as root. Set new password. Exit MySQL and restart MySQL server.

# /etc/init.d/mysql stop
# mysqld_safe --skip-grant-tables &
# mysql -u root
mysql> use mysql;
mysql> update user set password=PASSWORD("newrootpassword") where User='root';
mysql> flush privileges;
mysql> quit
# /etc/init.d/mysql stop
# /etc/init.d/mysql start
  • Set a root password if there is on root password.

# mysqladmin -u root password newpassword
  • Update a root password.

# mysqladmin -u root -p oldpassword newpassword
  • Allow the user "tom" to connect to the server from localhost using the password "passwd". Login as root. Switch to the MySQL db. Give privs. Update privs.

# mysql -u root -p
mysql> use mysql;
mysql> grant usage on *.* to tom@localhost identified by 'passwd';
mysql> flush privileges;
  • Give user privilages for a db. Login as root. Switch to the MySQL db. Grant privs. Update privs.

# mysql -u root -p
mysql> use mysql;
mysql> INSERT INTO db (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv) VALUES ('%','databasename','username','Y','Y','Y','Y','Y','N');
mysql> flush privileges;


or


mysql> grant all privileges on databasename.* to username@localhost;
mysql> flush privileges;
  • To update info already in a table.

mysql> UPDATE [table name] SET Select_priv = 'Y',Insert_priv = 'Y',Update_priv = 'Y' where [field name] = 'user';
  • Delete a row(s) from a table.

mysql> DELETE from [table name] where [field name] = 'whatever';
  • Update database permissions/privilages.

mysql> flush privileges;
  • Delete a column.

mysql> alter table [table name] drop column [column name];
  • Add a new column to db.

mysql> alter table [table name] add column [new column name] varchar (20);
  • Change column name.

mysql> alter table [table name] change [old column name] [new column name] varchar (50);
  • Make a unique column so you get no dupes.

mysql> alter table [table name] add unique ([column name]);
  • Make a column bigger.

mysql> alter table [table name] modify [column name] VARCHAR(3);
  • Delete unique from table.

mysql> alter table [table name] drop index [colmn name];
  • Load a CSV file into a table.

mysql> LOAD DATA INFILE '/tmp/filename.csv' replace INTO TABLE [table name] FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' (field1,field2,field3);
  • Dump all databases for backup. Backup file is sql commands to recreate all db's.

# [mysql dir]/bin/mysqldump -u root -ppassword --opt >/tmp/alldatabases.sql

or # [mysql dir]/bin/mysqldump -u root -ppassword --all-databases >/tmp/alldatabases.sql
  • Dump one database for backup.

# [mysql dir]/bin/mysqldump -u username -ppassword --databases databasename >/tmp/databasename.sql
  • Dump a table from a database.

# [mysql dir]/bin/mysqldump -c -u username -ppassword databasename tablename > /tmp/databasename.tablename.sql
  • Restore database (or database table) from backup.

# [mysql dir]/bin/mysql -u username -ppassword databasename < /tmp/databasename.sql 

  • Restore all databases from backup with --all-databases option.

# [mysql dir]/bin/mysql -u root -ppassword < /tmp/alldatabases.sql
  • Create Table Example 1.

mysql> CREATE TABLE [table name] (firstname VARCHAR(20), middleinitial VARCHAR(3), lastname VARCHAR(35),suffix VARCHAR(3),officeid VARCHAR(10),userid VARCHAR(15),username VARCHAR(8),email VARCHAR(35),phone VARCHAR(25), groups VARCHAR(15),datestamp DATE,timestamp time,pgpemail VARCHAR(255));
  • Create Table Example 2.

mysql> create table [table name] (personid int(50) not null auto_increment primary key,firstname varchar(35),middlename varchar(50),lastnamevarchar(50) default 'bato');

MYSQL Statements and clauses
ALTER DATABASE

ALTER TABLE

ALTER VIEW

ANALYZE TABLE

BACKUP TABLE

CACHE INDEX

CHANGE MASTER TO

CHECK TABLE

CHECKSUM TABLE

COMMIT

CREATE DATABASE

CREATE INDEX

CREATE TABLE

CREATE VIEW

DELETE

DESCRIBE

DO

DROP DATABASE

DROP INDEX

DROP TABLE

DROP USER

DROP VIEW

EXPLAIN

FLUSH

GRANT

HANDLER

INSERT

JOIN

KILL

LOAD DATA FROM MASTER

LOAD DATA INFILE

LOAD INDEX INTO CACHE

LOAD TABLE...FROM MASTER

LOCK TABLES

OPTIMIZE TABLE

PURGE MASTER LOGS

RENAME TABLE

REPAIR TABLE

REPLACE

RESET

RESET MASTER

RESET SLAVE

RESTORE TABLE

REVOKE

ROLLBACK

ROLLBACK TO SAVEPOINT

SAVEPOINT

SELECT

SET

SET PASSWORD

SET SQL_LOG_BIN

SET TRANSACTION

SHOW BINLOG EVENTS

SHOW CHARACTER SET

SHOW COLLATION

SHOW COLUMNS

SHOW CREATE DATABASE

SHOW CREATE TABLE

SHOW CREATE VIEW

SHOW DATABASES

SHOW ENGINES

SHOW ERRORS

SHOW GRANTS

SHOW INDEX

SHOW INNODB STATUS

SHOW LOGS

SHOW MASTER LOGS

SHOW MASTER STATUS

SHOW PRIVILEGES

SHOW PROCESSLIST

SHOW SLAVE HOSTS

SHOW SLAVE STATUS

SHOW STATUS

SHOW TABLE STATUS

SHOW TABLES

SHOW VARIABLES

SHOW WARNINGS

START SLAVE

START TRANSACTION

STOP SLAVE

TRUNCATE TABLE

UNION

UNLOCK TABLES

USE

String Functions
AES_DECRYPT

AES_ENCRYPT

ASCII

BIN

BINARY

BIT_LENGTH

CHAR

CHAR_LENGTH

CHARACTER_LENGTH

COMPRESS

CONCAT

CONCAT_WS

CONV

DECODE

DES_DECRYPT

DES_ENCRYPT

ELT

ENCODE

ENCRYPT

EXPORT_SET

FIELD

FIND_IN_SET

HEX

INET_ATON

INET_NTOA

INSERT

INSTR

LCASE

LEFT

LENGTH

LOAD_FILE

LOCATE

LOWER

LPAD

LTRIM

MAKE_SET

MATCH    AGAINST

MD5

MID

OCT

OCTET_LENGTH

OLD_PASSWORD

ORD

PASSWORD

POSITION

QUOTE

REPEAT

REPLACE

REVERSE

RIGHT

RPAD

RTRIM

SHA

SHA1

SOUNDEX

SPACE

STRCMP

SUBSTRING

SUBSTRING_INDEX

TRIM

UCASE

UNCOMPRESS

UNCOMPRESSED_LENGTH

UNHEX

UPPER

Date and Time Functions
ADDDATE

ADDTIME

CONVERT_TZ

CURDATE

CURRENT_DATE

CURRENT_TIME

CURRENT_TIMESTAMP

CURTIME

DATE

DATE_ADD

DATE_FORMAT

DATE_SUB

DATEDIFF

DAY

DAYNAME

DAYOFMONTH

DAYOFWEEK

DAYOFYEAR

EXTRACT

FROM_DAYS

FROM_UNIXTIME

GET_FORMAT

HOUR

LAST_DAY

LOCALTIME

LOCALTIMESTAMP

MAKEDATE

MAKETIME

MICROSECOND

MINUTE

MONTH

MONTHNAME

NOW

PERIOD_ADD

PERIOD_DIFF

QUARTER

SEC_TO_TIME

SECOND

STR_TO_DATE

SUBDATE

SUBTIME

SYSDATE

TIME

TIMEDIFF

TIMESTAMP

TIMESTAMPDIFF

TIMESTAMPADD

TIME_FORMAT

TIME_TO_SEC

TO_DAYS

UNIX_TIMESTAMP

UTC_DATE

UTC_TIME

UTC_TIMESTAMP

WEEK

WEEKDAY

WEEKOFYEAR

YEAR

YEARWEEK

Mathematical and Aggregate Functions
ABS

ACOS

ASIN

ATAN

ATAN2

AVG

BIT_AND

BIT_OR

BIT_XOR

CEIL

CEILING

COS

COT

COUNT

CRC32

DEGREES

EXP

FLOOR

FORMAT

GREATEST

GROUP_CONCAT

LEAST

LN

LOG

LOG2

LOG10

MAX

MIN

MOD

PI

POW

POWER

RADIANS

RAND

ROUND

SIGN

SIN

SQRT

STD

STDDEV

SUM

TAN

TRUNCATE

VARIANCE

Flow Control Functions
CASE

IF

IFNULL

NULLIF

Command-Line Utilities
comp_err

isamchk

make_binary_distribution

msql2mysql

my_print_defaults

myisamchk

myisamlog

myisampack

mysqlaccess

mysqladmin

mysqlbinlog

mysqlbug

mysqlcheck

mysqldump

mysqldumpslow

mysqlhotcopy

mysqlimport

mysqlshow

perror

Perl API - using functions and methods built into the Perl DBI with MySQL
available_drivers

begin_work

bind_col

bind_columns

bind_param

bind_param_array

bind_param_inout

can

clone

column_info

commit

connect

connect_cached

data_sources

disconnect

do

dump_results

err

errstr

execute

execute_array

execute_for_fetch

fetch

fetchall_arrayref

fetchall_hashref

fetchrow_array

fetchrow_arrayref

fetchrow_hashref

finish

foreign_key_info

func

get_info

installed_versions


last_insert_id

looks_like_number

neat

neat_list

parse_dsn

parse_trace_flag

parse_trace_flags

ping

prepare

prepare_cached

primary_key

primary_key_info

quote

quote_identifier

rollback

rows

selectall_arrayref

selectall_hashref

selectcol_arrayref

selectrow_array

selectrow_arrayref

selectrow_hashref

set_err

state

table_info

table_info_all

tables

trace

trace_msg

type_info

type_info_all

Attributes for Handles

PHP API - using functions built into PHP with MySQL
mysql_affected_rows

mysql_change_user

mysql_client_encoding

mysql_close

mysql_connect

mysql_create_db

mysql_data_seek

mysql_db_name

mysql_db_query

mysql_drop_db

mysql_errno

mysql_error

mysql_escape_string

mysql_fetch_array

mysql_fetch_assoc

mysql_fetch_field

mysql_fetch_lengths

mysql_fetch_object

mysql_fetch_row

mysql_field_flags

mysql_field_len

mysql_field_name

mysql_field_seek

mysql_field_table

mysql_field_type

mysql_free_result

mysql_get_client_info

mysql_get_host_info

mysql_get_proto_info

mysql_get_server_info

mysql_info

mysql_insert_id

mysql_list_dbs

mysql_list_fields

mysql_list_processes

mysql_list_tables

mysql_num_fields

mysql_num_rows

mysql_pconnect

mysql_ping

mysql_query

mysql_real_escape_string

mysql_result

mysql_select_db

mysql_stat

mysql_tablename

mysql_thread_id

mysql_unbuffered_query

Installing Lsyncd to Create a Mirror Server on CentOS and Redhat

LSYNCD (Live SYNCing Daemon) is a flexible cross-platform synchronization tool. It uses rsync underneath it. lsync runs as a daemon and continuously runs a sync between the source and the mirror. No cron is required to maintain the sync.


Steps to deploy Lsyncd : (login as root and execute the following steps)

1. Create the password-less logging using ssh keys between the source(server1) & mirror(server2) servers.

# ssh-keygen

Press enter to create key without any passphrase.

A file /root/.ssh/id_rsa.pub will be created on server1

# cp /root/.ssh/id_rsa.pub /root/.ssh/authorized_keys


Run the same command on server2.

A file /root/.ssh/id_rsa.pub will be created on server2

# cp /root/.ssh/id_rsa.pub /root/.ssh/authorized_keys


Now open the authorized_keys file in server1 and append the contents in authorized_keys file of server2. Do the same from authorized_keys file in server2 to server1. (Now both the authorized_keys files should be the same with each others keys in them).

Login from both the servers so that the "known hosts" file is updated.

2. # yum install rsync

3. Install the lsyncd from dag wieers repository.   

Add a repo file dag.repo in the /etc/yum.repos.d/ directory with the following contents:

[dag]
name=Dag RPM Repository for Red Hat Enterprise Linux
baseurl=http://apt.sw.be/redhat/el5/en/i386/rpmforge     ## Change i386 to x86_64 if on a 64bit machine
gpgcheck=0
enabled=1

4. # yum --enablerepo=dag -y install lsyncd

5. Create a config file named /etc/lsyncd.conf and Put the following contents in it (change the target source directory & IP:/path according to your requirement):


 settings = {
   logfile    = "/var/log/lsyncd.log",
}

sync{default.rsync, source="/var/www/lsync", target="10.10.10.246:/var/www/lsync", rsyncOps="-rltvu"}


6. Create a log file :

# touch /var/log/lsyncd.log

7. Start the Services:
   # service lsyncd start
   # ckhconfig lsyncd on

That is it! You have got a live mirror server. Now if you want to mirror ''both-ways'' then you can install lsync in the server2 also and repeat the same steps.

Other Examples of lsyncd (Multiple Mirrors):

Below is the lsyncd.conf that duplicates /var/www/html on the master server to the 4 targets (mirrors) with the same path:

settings = {
   delay        = 1,
   maxProcesses = 5,
   statusFile   = "/tmp/lsyncd.status",
   logfile      = "/var/log/lsyncd.log",
}

targetlist = {
 "10.0.1.23:/var/www/html",
 "10.0.1.24:/var/www/html",
 "10.0.1.25:/var/www/html",
 "10.0.1.26:/var/www/html"
}

for _, server in ipairs(targetlist) do
  sync{ default.rsync,
    source="/var/www/html",
    rsyncOpts="-rltvupgo",
    target=server
  }
end
 
 
So use this powerful tool and leave comments if you liked it or need help. 
 

Installing Collabnet SVN on CentOS & Redhat


Collabnet SVN provides a good Web-GUI to do mundane SVN administration via webinterface. Here's a howto to get it installed on CentOS.

Prerequisites:

1)    Java 1.6 JRE/JDK must be installed.

2)    Python 2.4 or higher version must be installed.

3)    Download CollabNetSubversionEdge-2.2.1_linux (32/64 bit)

WARNING:
Note: Do not untar CollabNetSubversionEdge-2.2.1_linux package using root or sudo. This will cause the UID/GID on the files to carry the values from the collabnet build system instead of being reset.
1.      Install JAVA Runtime Environment package from Add/Remove Software (System>Administration>Add/Remove Software) by searching for Java/JRE.
OR
# yum install java-1.6.0-openjdk.x86_64
  2.      After Java installation is over, type the following command in Terminal window.
                    export JAVA_HOME=/usr/lib/jvm/jre-1.6.0-openjdk.x86_64
  And also add the above line to /etc/profile (at the bottom of the file)
  #sudo gedit /etc/profile
  OR
  #sudo vi /etc/profile
       Now you can check the installed java version by the following command.
      # java –version
      Probably this would be the output:
      java version "1.6.0_22"
       OpenJDK Runtime Environment (IcedTea6 1.10.4) (rhel-1.42.1.10.4.el6_2-x86_64)
       OpenJDK 64-Bit Server VM (build 20.0-b11, mixed mode) 

3.      Add any normal (non-root) user to etc/sudoers file or by the following command.

# visudo

And add the following line anywhere in the file.

username  ALL=(ALL)  ALL



4.      Now migrate to non-root (normal) user and select the folder where you want to install CollabNet Subversion Edge. I would recommend you to install the Subversion in the normal user folder. It can be Downloads/ Documents/ Desktop etc.

[root@localhost ]# su – username



[username@localhost]$ mkdir opt/subversion

Note: If you are not able to create folder “subversion” in “opt” directory, then you can create it through “root” or “sudo”.

[username@localhost]$ cd opt/subversion

[username@localhost]$ sudo chmod o+wx /opt/subversion/

Now move the downloaded CollabNetSubversionEdge-2.2.1-linux-x86_64.tar.gz package to opt/subversion.

5.      Now Untar the CollabNetSubversionEdge-2.2.1-linux-x86_64.tar.gz package by the following command.

[username@localhost subversion]$ tar zxf CollabNetSubversionEdge-2.2.1_linux-x86_64.tar.gz  

Note: The above command will create a folder named “csvn”.

[username@localhost subversion]$ cd csvn

Now we will install the application so that subversion will start automatically when the server restarts. For doing this type the following command.

Note: To set up the server so that it starts automatically when rebooted, you will need to have root/sudo access and follow these steps.

Edit the configuration. When a process is started at server startup it runs as root. You do not want the CSVN console to run as root, you want it to run as a specific user -- whatever your login user is.
  1. To do this, edit the file data/conf/csvn.conf.

$ vi data/conf/csvn.conf
  1. Scroll down a little bit until you see #RUN_AS_USER= . Uncomment it out and add your username.

Example:

RUN_AS_USER= username
  1. Save the changes.

[username@localhost csvn]$ sudo –E bin/csvn install

Now we will start the server. Be sure that you are not logged in as root.

[username@localhost csvn]$ bin/csvn start
This will take a few minutes and the script will loop until it sees that the server is running.
Note: If the server does not start, then try starting the server with this command:
 [username@localhost csvn]$ bin/csvn console
 6.      Add the following line to /etc/sysconfig/iptables
  # iptables -A INPUT –p tcp --dport 3343 –j ACCEPT
  Restart firewall to update the changes
  # service iptables restart
  Installation is done, now open the following link:
username: admin 
password: admin
  Note: If you are not able to see your CSVN server on the browser, then just disabled the your system Firewall by entering setup command in the terminal window.
# setup
Or 
Go to System>Administration>Firewall and disable it.
  Note: You can change the IP address of your subversion server with your machine IP address by editing 
 opt/subversion/csvn/data/conf/csvn.conf file (at line no. 62) by the following command.
$ sudo vi data/conf/csvn.conf
  OR
$ sudo gedit  data/conf/csvn.conf
Subversion Edge also starts an SSL-protected version using a self-signed SSL certificate.
You can access the SSL version on this URL:

Directory Hierarchy of CPanel

The following is the directory structure of cpanel. This is generic but can be useful for newbies.

Apache

/usr/local/apache
+ bin- apache binaries are stored here – httpd, apachectl, apxs
+ conf – configuration files – httpd.conf
+ cgi-bin
+ domlogs – domain log files are stored here
+ htdocs
+ include – header files
+ libexec – shared object (.so) files are stored here – libphp4.so,mod_rewrite.so
+ logs – apache logs – access_log, error_log, suexec_log
+ man – apache manual pages
+ proxy -
+ icons -
Cpanel script to restart apache – /scripts/restartsrv_httpd
Start httpd with ssl – /etc/init.d/httpd startssl

DNS – Named(Bind)

Program: /usr/sbin/named
Init Script: /etc/rc.d/init.d/named
/etc/named.conf
db records:/var/named/
/var/log/messages

Exim

Conf : /etc/exim.conf – exim main configuration file
/etc/localdomains – list of domains allowed to relay mail
Log : /var/log/exim_mainlog – incoming/outgoing mails are logged here
/var/log/exim_rejectlog – exim rejected mails are reported here
/var/log/exim_paniclog – exim errors are logged here
Mail queue: /var/spool/exim/input
Cpanel script to restart exim – /scripts/restartsrv_exim
Email forwarders and catchall address file – /etc/valiases/domainname.com
Email filters file – /etc/vfilters/domainname.com
POP user authentication file – /home/username/etc/domainname/passwd
catchall inbox – /home/username/mail/inbox
POP user inbox – /home/username/mail/domainname/popusername/inbox
POP user spambox – /home/username/mail/domainname/popusername/spam
Program : /usr/sbin/exim (suid – -rwsr-xr-x 1 root root )
Init Script: /etc/rc.d/init.d/exim

Mysql

Program : /usr/bin/mysql
Init Script : /etc/rc.d/init.d/mysql
Conf : /etc/my.cnf, /root/.my.cnf
Data directory – /var/lib/mysql – Where all databases are stored.
Database naming convention – username_dbname (eg: john_sales)
Permissions on databases – drwx 2 mysql mysql
Socket file – /var/lib/mysql/mysql.sock, /tmp/ mysql.sock

SSHD

Program :/usr/local/sbin/sshd
Init Script :/etc/rc.d/init.d/sshd
/etc/ssh/sshd_config
Log: /var/log/messages

ProFTPD

Program :/usr/sbin/proftpd
Init Script :/etc/rc.d/init.d/proftpd
Conf: /etc/proftpd.conf
Log: /var/log/messages, /var/log/xferlog
FTP accounts file – /etc/proftpd/username – all ftp accounts for the domain are listed here

Pure-FTPD

Program : /usr/sbin/pure-ftpd
Init Script :/etc/rc.d/init.d/pure-ftpd
Conf: /etc/pure-ftpd.conf
Anonymous ftp document root – /etc/pure-ftpd/ip-address

Perl

Program :/usr/bin/perl
Directory :/usr/lib/perl5/5.6.1/

PHP

Program :/usr/local/bin/php, /usr/bin/php
ini file: /usr/local/lib/php.ini – apache must be restarted after any change to this file

Cpanel

/usr/local/cpanel
+ 3rdparty/ – tools like fantastico, mailman files are located here
+ addons/ – AdvancedGuestBook, phpBB etc
+ base/ – phpmyadmin, squirrelmail, skins, webmail etc
+ bin/ – cpanel binaries
+ cgi-sys/ – cgi files like cgiemail, formmail.cgi, formmail.pl etc
+ logs/ – cpanel access log and error log
+ whostmgr/ – whm related files

WHM

/var/cpanel – whm files
+ bandwidth/ – rrd files of domains
+ username.accts – reseller accounts are listed in this files
+ packages – hosting packages are listed here
+ root.accts – root owned domains are listed here
+ suspended – suspended accounts are listed here
+ users/ – cpanel user file – theme, bwlimit, addon, parked, sub-domains all are listed in this files
+ zonetemplates/ – dns zone template files are taken from here

Important cpanel/whm files

/usr/local/apache/conf/httpd.conf – apache configuration file
/etc/exim.conf – mail server configuration file
/etc/named.conf – name server (named) configuration file
/etc/proftpd.conf – proftpd server configuration file
/etc/pure-ftpd.conf – pure-ftpd server configuration file
/etc/valiases/domainname – catchall and forwarders are set here
/etc/vfilters/domainname – email filters are set here
/etc/userdomains – all domains are listed here – addons, parked,subdomains along with their usernames
/etc/localdomains – exim related file – all domains should be listed here to be able to send mails
/var/cpanel/users/username – cpanel user file
/var/cpanel/cpanel.config – cpanel configuration file ( Tweak Settings )*
/etc/cpbackup-userskip.conf -
/etc/sysconfig/network – Networking Setup*
/etc/hosts -
/var/spool/exim -
/var/spool/cron -
/etc/resolv.conf – Networking Setup–> Resolver Configuration
/etc/nameserverips – Networking Setup–> Nameserver IPs ( FOr resellers togive their nameservers )
/var/cpanel/resellers – For addpkg, etc permissions for resellers.
/etc/chkserv.d – Main >> Service Configuration >> Service Manager *
/var/run/chkservd – Main >> Server Status >> Service Status *
/var/log/dcpumon – top log process
/root/cpanel3-skel – skel directory. Eg: public_ftp, public_html. (AccountFunctions–>Skeleton Directory )*
/etc/wwwacct.conf – account creation defaults file in WHM (Basic cPanel/WHMSetup)*
/etc/cpupdate.conf – Update Config *
/etc/cpbackup.conf – Configure Backup*
/etc/clamav.conf – clamav (antivirus configuration file )
/etc/my.cnf – mysql configuration file
/usr/local/Zend/etc/php.ini OR /usr/local/lib/php.ini – php configuration file
/etc/ips – ip addresses on the server (except the shared ip) (IP Functions–>Show IP Address Usage )*
/etc/ipaddrpool – ip addresses which are free
/etc/ips.dnsmaster – name server ips
/var/cpanel/Counters – To get the counter of each users.
/var/cpanel/bandwidth – To get bandwith usage of domains