Resetting a forgotten MySQL root password
September 19, 2009 at 8:34 pm | In DataBases | Leave a CommentResetting 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.
However 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!
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 stop
Now 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]: started
Here 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
Bye
Now 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
Bye
If 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.
ref from http://www.debian-administration.org/articles/442
zip on linux
August 31, 2009 at 11:39 am | In Linux Basics | Leave a Commentzip the files and folders:
Syntex:
zip -9 -r <zip file> <folder name>
Where,
-9 —> for best compression.
-r Travel the directory structure recursively
The compressed file works fine with Windows XP compression tool.
Ex:
[root@linux home]# zip -9 -r test.zip test/
To zip a single file:
zip -9 <zip file> <filename>
grep mv pipe (simple script)
August 20, 2009 at 12:48 pm | In mailserver | Leave a Comment<!– @page { size: 8.5in 11in; margin: 0.79in } P { margin-bottom: 0.08in } –>
This useful while we need to manually delete the mail delivery mails in queues
The following command for two action doing(files with matches):
1.First Action is searching using word ‘Subject : failure notice’ in mails in the qmail queue.
2. Second Action is move that collected matched emails into the ‘garbage’ folder. Afterthat we delete that folder only..
Note: Before using this simple script,we need to create ‘garbage’ folder
grep -l -r ‘Subject : failure notice’ /var/qmail/queue/mess/0 | while read f; do mv “$f” garbage; done
-l, –files-with-matches
Suppress normal output; instead print the name of each input
file from which output would normally have been printed. The
scanning will stop on the first match.
-R, -r, –recursive
Read all files under each directory, recursively; this is equiv-
alent to the -d recurse option.
garbage — > folder.. we want to create it..
This following command used for files without mach and move that without match files into the single folder (out):
grep -L -r ‘test’ /home/* | while read f; do mv “$f” garbage; done
-L, –files-without-match
Suppress normal output; instead print the name of each input
file from which no output would normally have been printed. The
scanning will stop on the first match.
-R, -r, –recursive
Read all files under each directory, recursively; this is equiv-
alent to the -d recurse option.
How do I View Messages in the Qmail Queue?
August 20, 2009 at 12:00 pm | In mailserver | Leave a CommentYou can view all messages in the email queue.
To Display all Messages in the Email Queue
-
Log in to your server using SSH.
-
At the command prompt, type:
/var/qmail/bin/qmail-qstat
You can see how many mails in the qmailqueue
-
To list multiple messages in the queue, type:
/var/qmail/bin/qmail-qread
/etc/aliases File
August 13, 2009 at 6:35 pm | In mailserver | Leave a CommentYou can think of the /etc/aliases file as a mailing list file.
The first column has the mailing list name (sometimes called a virtual mailbox)
The second column has the members of the mailing list separated by commas.
To start, sendmail searches the first column of the file for a match.
If there is no match, then sendmail assumes the recipient is a regular user on the local server and deposits the mail in their mailbox.
If it finds a match in the first column, sendmail notes the nickname entry in the second column. It then searches for the nickname again in the first column to see if the recipient isn’t on yet another mailing list.
If sendmail doesn’t find a duplicate, it assumes the recipient is a regular user on the local server and deposits the mail in their mailbox.
If the recipient is a mailing list, then sendmail goes through the process all over again to determine if any of the members is on yet another list, and when it is all finished, they all get a copy of the e-mail message.
In the example that follows,
you can see that mail sent to users bin, daemon, lp, shutdown, apache, named, and so on by system processes will all be sent to user (or mailing list) root.
In this case, root is actually an alias for a mailing list consisting of user paul and webmaster@example.com.
# Basic system aliases -- these MUST be present. mailer-daemon: postmaster postmaster: root # General redirections for pseudo accounts. bin: root daemon: root ... ... abuse: root # trap decode to catch security attacks decode: root # Person who should get root's mail root: paul,webmaster@example.com
Notice that there are no spaces between the mailing list entries for root: You will get errors if you add spaces.
Note:
The default /etc/aliases file installed with RedHat / Fedora has the last line of this sample commented out with a #, you may want to delete the comment and change user paul to another user. Also after editing this file, you’ll have to convert it into a sendmail readable database file named /etc/aliases.db. Here is the command to do that:
[root@bigboy tmp]# newaliases
In this simple mailing list example,
mail sent to root actually goes to user account paul and webmaster@example.com
Which User Should Really Receive The Mail?
August 13, 2009 at 6:08 pm | In mailserver | Leave a CommentThe /etc/mail/virtusertable file
The /etc/mail/virtusertable file contains a set of simple instructions on what to do with received mail.
The first column lists the target email address
The second column lists the local user’s mail box, a remote email address, or a mailing list entry in the /etc/aliases file to which the email should be forwarded.
If there is no match in the virtusertable file, sendmail checks for the full email address in the /etc/aliases file.
webmaster@example.com webmasters @example.com paul sales@redhat.com sales@example.com paul@redhat.com paul finance@redhat.com paul @redhat.com error:nouser User unknown
In this example,
mail sent to:
- webmaster@example.com will go to local user (or mailing list) webmasters, all other mail to example.com will go to local user paul.
- sales@redhat.com will go to the sales department @example.com.
- paul and finance @redhat.com goes to local user (or mailing list) paul
All other users @redhat.com receive a bounce back message stating “User unknown”.
After editing the /etc/mail/virtusertable file,
you have to convert it into a sendmail-readable database file named /etc/mail/virtusertable.db with two commands:
[root@bigboy tmp]# cd /etc/mail [root@bigboy mail]# make
How to Backup/Restore a MySQL Database
August 3, 2009 at 7:12 pm | In DataBases | Leave a CommentSimple Copy
The easiest method is to simply copy the binary database files. However this may create problems and is not the recommended copying method.
For example,
the different ways of handling case-sensitivity between Unix and Windows means that a database copied from one system to the other may become corrupt.
Using the mysqldump Command
The mysqldump command creates a text version of the database. Specifically, it creates a list of SQL statements which can be used to restore/recreate the original database.
The syntax is:
$ mysqldump -u [uname] -p[pass] [dbname] > [backupfile.sql]
| [uname] | Your database username |
| [pass] | The password for your database |
| [dbname] | The name of your database |
| [backupfile.sql] | The filename for your database backup |
You can dump a table, a database, or all databases.
Example:
To dump all MySQL databases on the system, use the –all-databases shortcut:
$ mysqldump -u root -p –all-databases > [backupfile.sql]
Restoring a MySQL Database
Use this method to rebuild a database from scratch:
$ mysql -u [username] -p [password] [database_to_restore] < [backupfile]
Use this method to import into an existing database (i.e. to restore a database that already exists):
$ mysqlimport [options] database textfile1
To restore custsupport.sql dump back to your ‘Customers’ MySQL database, you’d use:
$ mysqlimport -u sadmin -p pass21 Customers custsupport.sql
Basic TIps
August 3, 2009 at 6:58 pm | In Linux Basics | Leave a Comment
1) Use tail –f to watch log file in real time, advantage is simple you can spot error or warning message in real time. tail –f /path/to/log/file
Example(s): # tail –f /var/log/maillog
2) Use telnet command to see if you get response or not. Sometime you will also see some informative message:
telnet ip port
Example(s): # telnet localhost 53 # telnet localhost 25
3) Make sure you can see PID of your service. pidof service-name
cat /var/run/service.pid
Example(s): # pidof sshd # cat /var/run/sshd.pid
4) You need to make sure that your DNS server or third party DNS server (ISP) is accessible. This is an important step, as many network services depend upon DNS; especially sendmail/postfix or Squid etc for example. Run dig or nslookup. No timeout should occur. # dig your-domain.com
# nslookup gw.isp.com
# more /etc/resolv.conf
5) For networking troubleshooting, make sure your ip address configuration is right, gateway, routine, hostname etc all configured. Here is list of tools on RedHat Linux to verify or modify information:
Hostname verification or setup tools
- hostname : To get hostname of server.
- hostname –s : To get FQDN hostname of server
- more /etc/sysconfig/network : To setup hostname and networking can enabled or disabled.
- dnsdomainname : List or setup domainname.
- more /etc/hosts :Make sure at least localhost entry do exist.
Ethernet configuration tools
- ifconfig : To see running network card information.
- ifconfig eth0 up|down : To enable|disable network interface
- service network reload|restart|stop|start : To reload (after changed made in ip config file)|restart|stop|start network interface with all properties.
- route|netstat –rn : To print routing table
- ping ip-address : To see if host is alive or dead
- more /etc/modules.conf : To see your network card configuration alias for eth0 exists or not.
- lsmod : To list loaded modules (read as drivers), here you need to see that eth0 module is loaded or not, if not loaded then use insmod to insert (load) driver.
- dhclient : Dynamic Host Configuration Protocol Client, run this if your Ethernet card is not getting ip from DHCP box on startup; this command does by default shows useful information.
To see if service blocked because of access control
- iptables –n –L : To list all iptable rules; useful to see if firewall blocks service or not.
- service iptables stop|start : To start|stop iptables
- more /etc/xinetd.conf
- more /etc/xinetd.conf/SERVICENAME = To list configuration of xinetd server. Again useful to see if firewall xinetd based security blocks service or not (xinetd includes host-based and time-based access control)
- more /etc/hosts.allow : To see list of hosts allowed to access service.
- more /etc/hosts.deny : To see list of hosts NOT allowed to access service. NOTE first TCP wrappers (hosts.allow|hosts.deny) checked and then xinetd-based access control checked.
- more /etc/path/to/application.conf : See your application configuration file for access control. For example smb.conf and many other applications/services got own access control list in application. You need to check that as well.
Ports and its use
August 3, 2009 at 6:55 pm | In Linux Basics | Leave a Comment|
Port Number |
Description |
| 1 | TCP Port Service Multiplexer (TCPMUX) |
| 5 | Remote Job Entry (RJE) |
| 7 | ECHO |
| 18 | Message Send Protocol (MSP) |
| 20 | FTP — Data |
| 21 | FTP — Control |
| 22 | SSH Remote Login Protocol |
| 23 | Telnet |
| 25 | Simple Mail Transfer Protocol (SMTP) |
| 29 | MSG ICP |
| 37 | Time |
| 42 | Host Name Server (Nameserv) |
| 43 | WhoIs |
| 49 | Login Host Protocol (Login) |
| 53 | Domain Name System (DNS) |
| 69 | Trivial File Transfer Protocol (TFTP) |
| 70 | Gopher Services |
| 79 | Finger |
| 80 | HTTP |
| 103 | X.400 Standard |
| 108 | SNA Gateway Access Server |
| 109 | POP2 |
| 110 | POP3 |
| 115 | Simple File Transfer Protocol (SFTP) |
| 118 | SQL Services |
| 119 | Newsgroup (NNTP) |
| 137 | NetBIOS Name Service |
| 139 | NetBIOS Datagram Service |
| 143 | Interim Mail Access Protocol (IMAP) |
| 150 | NetBIOS Session Service |
| 156 | SQL Server |
| 161 | SNMP |
| 179 | Border Gateway Protocol (BGP) |
| 190 | Gateway Access Control Protocol (GACP) |
| 194 | Internet Relay Chat (IRC) |
| 197 | Directory Location Service (DLS) |
| 389 | Lightweight Directory Access Protocol (LDAP) |
| 396 | Novell Netware over IP |
| 443 | HTTPS |
| 444 | Simple Network Paging Protocol (SNPP) |
| 445 | Microsoft-DS |
| 458 | Apple QuickTime |
| 546 | DHCP Client |
| 547 | DHCP Server |
| 563 | SNEWS |
| 569 | MSN |
| 1080 | Socks |
Virtual Memory Statistics ( vmstat )
August 1, 2009 at 12:14 pm | In Linux Basics | Leave a Commentvmstat -
vmstat reports virtual memory statistics of process, virtual memory, disk, trap, and CPU activity.
On multicpu systems , vmstat averages the number of CPUs into the output. For per-process statistics .Without options, vmstat displays a one-line summary of the virtual memory activity since the system was booted.
- SYNTAX:
Basic syntax is vmstat <options> interval count
option – let you specify the type of information needed such as paging -p , cache -c ,.interrupt -i etc.
if no option is specified information about process , memory , paging , disk ,interrupts & cpu is displayed .
interval – is time period in seconds between two samples . vmstat 4 will give data at each 4 seconds interval.
- count – is the number of times the data is needed . vmstat 4 5 will give data at 4 seconds interval 5
- times.
EXAMPLE:
The following command displays a summary of what the system
is doing every five seconds.
vmstat 4
procs memory page disk faults cpu
r b w swap free re mf pi p fr de sr s0 s1 s2 s3 in sy cs us sy id
0 0 0 11456 4120 1 41 19 1 3 0 2 0 4 0 0 48 112 130 4 14 82
0 0 1 10132 4280 0 4 44 0 0 0 0 0 23 0 0 211 230 144 3 35 62
0 0 1 10132 4616 0 0 20 0 0 0 0 0 19 0 0 150 172 146 3 33 64
0 0 1 10132 5292 0 0 9 0 0 0 0 0 21 0 0 165 105 130 1 21 78
|
- The fields of vmstat’s display are
procs
r in run queue
b blocked for resources I/O, paging etc.
w swappedmemory (in Kbytes)
swap – amount of swap space currently available
free – size of the free listpage ( in units per second).
re page reclaims – see -S option for how this field is modified.
mf minor faults – see -S option for how this field is modified.
pi kilobytes paged in
po kilobytes paged out
fr kilobytes freed
de anticipated short-term memory shortfall (Kbytes)
sr pages scanned by clock algorithmdisk ( operations per second )
- There are slots for up to four disks, labeled with a single letter and number.
- The letter indicates the type of disk (s = SCSI, i = IPI, etc) . The number is
- the logical unit number.
faults
in (non clock) device interrupts
sy system calls
cs CPU context switchescpu – breakdown of percentage usage of CPU time. On multiprocessors this is an a
- verage across all processors.
us user time
sy system time
id idle time
Blog at WordPress.com. | Theme: Pool by Borja Fernandez.
Entries and comments feeds.