Monday, December 5, 2011

Changing user password

When you install mysql using yum on a rpm based machine, it's default root password is empty. To change it you can use mysqladmin command. The command is like this:
mysqladmin -u root password NEWPASSWORD
if you want to change a root with a existing password, you can use this:
mysqladmin -u root -p 'oldpassword' password NEWPASSWORD

Changing MySQL password for non-root user


To change a normal user password you can use the same syntax as changing root with existing password:
mysqladmin -u username -p 'oldpassword' password NEWPASSWORD

Chaning User Password using MySQL command


You can also used the MySQL command line to update user's password, MySQL stores username and passwords in a table inside MySQL database.

  1. Login to mysql server.
  2. Use mysql database.
  3. change password for username by entering:  update user set password = PASSWORD("NEWPASSWORD") where user='username';
  4. Lastly, restore the privileges: flush privileges;

Wednesday, November 30, 2011

Extracting tar.bz and tar.bz2 on Linux

To extract a tar.bz2 file, use this command:
tar -jxvf filename.tar.bz2
where j means  it's for bzip2, xz, lzip and lzma compress extension.

To extract a tar.gz file, the command is:
tar -zxvf filename.tar.gz
where z means it's for gzip, gunzip and ungzip compression extension
x is extract files from filename.tar.gz
v is to list all the file proccessed
f is to extract filename.tar.gz

if you want to specify the directory to where the extracted file go, use this command:
tar -xvzf file.tar.gz -C directory
where C means  put extracted file to directory

Friday, November 18, 2011

How to know MySQL activities: MysqlBinLog

Mysql has this new (maybe it's old) logging system called binary log (also called logbin). This consists of files containing events that describe  modifications to database contents. This file is saved in binary format by the server and the only way to read this binary file in human form is through mysqlbinlog utility. (By the way, this binary log is used by slave to replicated master's schema, so this is really a power file).

To execute mysqlbinlog in your terminal:
mysqbinlog [options] logfile
like:
mysqlbinlog /var/lib/mysql/localhost-bin.000005 
This command will then display the content of the binary file localhost-bin.000005. The content of this file is:

# at 430
#111110 21:55:34 server id 1  end_log_pos 537 Query thread_id=2 exec_time=0 error_code=0
SET TIMESTAMP=1320933334/*!*/;
update Company set name='hello' where id = 1
This 1st line which is "# at 430" means that the starting position of the event in the binary log file is 430. On the second line, the number's with colon is the timestamp of the event (this is when the event happen). The "server id 1" state that the event happen on server id number 1. "end_log_pos 537" indicates that the next event starts at 537. "thread_id=2" says that the thread that execute the event is id 2. "exec_time=0" means the time spent to execute the event. Lastly, the last line is the event executed by the server. As you can is it is an update.

For your server to log event as a binary file, you must first enable it. To enable, you must edit the my.cnf and append log-bin=path.

The normal formal of binary file logs is host_name-bin.###### and store in /var/bin/mysql directory.

Mysqbinlog I commonly use:


mysqbinlog /var/lib/mysql/localhost-bin.000005 > ~/mysql5.sql
This will put all the content of the logbin to the file mysql5.sql.

mysqbinlog --start-datetime="2011-11-11 11:11:11"  /var/lib/mysql/localhost-bin.000005
This will only display event that is log on and after 2011-11-11 11:11:11.

mysqbinlog --stop-datetime="2011-11-12 11:11:11" /var/lib/mysql/localhost-bin.000005
This will only display event that is log before 2011-11-12 11:11:11.

mysqbinlog --database=liims2 /var/lib/mysql/localhost-bin.000005

This will only display event that is invoke on database liims2.

Hope this will help you on using mysqlbinlog utility.

Reference:
http://dev.mysql.com/doc/refman/5.0/en/mysqlbinlog.html
http://dev.mysql.com/doc/refman/5.0/en/log-file-maintenance.html 

Saturday, November 12, 2011

Updating from Fedora 15 to Fedora 16

I have update my fedora 15 to 16 successfully today. So know I will share you the step.

First install the new Fedora 16 gpg key.
rpm --import https://fedoraproject.org/static/A82BA4B7.txt
then upgrade all packages using this commands.
yum update yum
yum clean all
yum --releasever=16 --disableplugin=presto distro-sync

you must have a root permission to do all the command above. so use sudo or log in as a root

Thursday, November 10, 2011

Maven - Installing Dependencies in your Local Computer

This is not something new to me. I just need to document this activity before I forget it again.

There are times when your .jar or api's are not in a central repositories for some reason. This is the time when installing dependencies in your local computer is applicable.

Here are the ways:
1. Install the dependency locally using the install plugin.

maven install:install-file -Dfile=foobar.jar -DgroupId=foo.bar -DartifactId=for-bar -Dversion=1 -Dpackaging=jar
2. Create your own repository and deploy it there. This is a fovrite method for companies with an intranet and need to be able to keep everyone in synch. There is a Maven goal called deploy:deploy-file which is simlar to the install:install-file goal.

On the two ways stated above, I normally used the 1st one if the project is been done by I alone. And if it is a team project, the 2nd ways is what I used.

Monday, October 10, 2011

Mysql Database Back/Restore

I have spent somethings research about this topic Back/Restore in Mysql and I found out that there are lot of ways to do this procedure but I choose this two:

  • Mysqldump - this will create a dumpfile (also called textfile) or it will display the dump file on your console.
    • Syntax: mysqldump -uMysqlUserl -p databaseName <>> filePath>
      • mysql -uroot -p liims2
        • after press enter will ask for password, display dumpfile of liims2 database as a whole in the console
      • mysql --complete-insert -uroot -pmysql liims2 pnpa 
        • display the dumpfile on console of pnpa table with complete insert query
      • mysql -uroot -pmysql liim2 >> /opt/mysql_backup.sql
        • backup all the data in liim2 database and put it on /opt/mysql_back.sql file
  • Mysql restore function - will restore you data from a dump file or text to a specific database
    • Syntax: mysql -uMysqlUserl -p DatabaseName << Backup.sql
      • mysql -uroot -pmysql liims2 << /opt/mysql_backup.sql
        • restore all that data defined on /opt/mysql_backup.sql to liims2 database

Sunday, June 26, 2011

Quiting to Live my LifeAgain

After more than 1 month of being addict to pockie ninja. I decided to quit, I have to live life again. Because of this game, I haven't being myself. No... I have been myself. The quitter, lazy me. The "Patabain baboy", the person I always am.

So... as a resolution for myself. I decided to quit that game that make me being me.

Sunday, May 8, 2011

pom.xml for webapp with spring, vaadin and junit.

1.
use: mvn archetype:generate
then select quick start or 106
2.
convert the package into eclipse project.
3.
create a /src/main/resources folder - the maven will put this data to classes
4.  pom.xml

    UTF-8
    4.8.2
    20040902.021138
    1.1.1
    20040616
    2.2
    1.1
    1.0.1
    1.2.0_rc2-dev
    3.6.4.Final
    3.0.5.RELEASE
    1.0
    2.1.2
    1.6.10
    1.3.1
    1.0.0.GA
    20030825.184428
    20030825.183949
    4.1.0.Beta1
 
  
 
 
            JBoss Repo
            https://repository.jboss.org/nexus/content/repositories/releases
            JBoss Repo
              
 

 
   
      junit
      junit
      ${junit.version}
      test
   
 org.hibernate
      hibernate-core
      ${hibernate.version}
   
 org.hibernate
      hibernate-entitymanager
      ${hibernate.version}
   
    org.springframework
    spring-core
    ${spring.version}
 
 
   org.springframework
   spring-beans
   ${spring.version}
 
   org.springframework
    spring-context
    ${spring.version}
 
 
  org.springframework
  spring-aspects
  ${spring.version}
  org.springframework
  spring-aop
  ${spring.version}  
org.springframework
spring-tx
${spring.version}
   org.apache.sling
   org.apache.sling.commons.log
${org.apache.sling.commons.log.version}
            org.hsqldb
            hsqldb
            2.0.0
            test
   
    org.aspectj
    aspectjrt
    ${aspectjrt.version}
 
javax.validation
validation-api
${validation-api.version}
   commons-dbcp
    commons-dbcp
    ${commons-dbcp.version}
   org.springframework
   spring-orm
   ${spring.version}
   commons-pool
   commons-pool
   ${commons-pool.version}
  org.hibernate
  hibernate-validator-annotation-processor
  ${hibernate-validator-annotation-processor.version}
     
 
 
 
 
          org.codehaus.mojo
    aspectj-maven-plugin
    ${org.codehaus.mojo.version}
 
   
     
        compile
test-compile
     
   
 
 
        1.6
        UTF-8
       
           
              org.springframework
              spring-aspects
           
       
     
org.apache.maven.plugins
maven-war-plugin
2.1-beta-1
org.apache.maven.plugins
maven-compiler-plugin
2.1
1.6
1.6
org.apache.maven.plugins
maven-resources-plugin
2.4.2
UTF-8
org.apache.maven.plugins
maven-assembly-plugin
2.2-beta-5
jar-with-dependencies
org.apache.maven.plugins
maven-deploy-plugin
2.5
org.codehaus.mojo
tomcat-maven-plugin
1.0
                org.apache.maven.plugins
                maven-jar-plugin
                2.3.1
               
                   
                        **/persistence.xml
**/applicationContext.xml
**/database.properties
**/log4j.properties
                   
               
           
        maven-antrun-plugin
         
          process-classes
           
              run
           
         
       
       
         
           
             
               
               
             
           
           
             
               
             
           
         
       
     
     
       org.apache.maven.plugins
       maven-checkstyle-plugin
       2.6
       
         dynobjx_checks.xml
       
   
   
org.apache.maven.plugins
maven-pmd-plugin
2.5
true
ISO-8859-1
30
1.6
 
 
 

applicationContext.xml

xmlns:aop="http://www.springframework.org/schema/aop" 
xmlns:context="http://www.springframework.org/schema/context" 
xmlns:jee="http://www.springframework.org/schema/jee" 
xmlns:tx="http://www.springframework.org/schema/tx" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://www.springframework.org/schema/aop 
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd   
http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd   
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context-3.0.xsd   
http://www.springframework.org/schema/jee 
http://www.springframework.org/schema/jee/spring-jee-3.0.xsd   
http://www.springframework.org/schema/tx 
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">

   
   

   
   

   
       
       
       
       
   
    
   
       
   
    
   
    
   
       
       
create-drop
   


persistence.xml

        org.hibernate.ejb.HibernatePersistence
       
           
           
           
           
           
           
           

           
value="com.informatics.GenericEntityPersistEventListener"/>
 

value="com.informatics.GenericEntityMergeEventListener"/>
       
   

Saturday, May 7, 2011

creating web application with vaadin framework

mvn archetype:generate -DarchetypeGroupId=com.vaadin -DarchetypeArtifactId=vaadin-archetype-clean -DarchetypeVersion=LATEST -DgroupId=com.dynamicobjx -DartifactId=VaadinHelloWorld -Dversion=1.0 -Dpackaging=war
-DgroupId - the main group package of your application and DartifactId is the name of your project. -Dpackaging is the method of packaging.

Thursday, April 21, 2011

Permission Command in Fedora


Introduction

Managing user permissions is an important administrative task. There are many commmand line tools available such as chownchgrp, and chmod. Use command line tools in either : symbolic and numeric mode to alter user permissions. The symbolic method uses symbols such as u+xr, and so on, to representing owners, groups, and permissions to alter permissions. The numeric method uses a numbering scheme.
Each file and directory has permissions for the owner (UID), group (GID), and everyone else (WORLD). The permissions for each group consist of three (binary) bits. There are 10 bits in total:--- --- --- (the 10th bit is the setuid or sticky bit - this will be described later). To alter permissions for owner use first three bits. Use the next three bits to alter permissions of group, and use the last three bits to alter permissions for everyone else.
Use the ls -l command to view file and directory permissions:
ls -l file1
-rw-rw-r-- 1 user1 group1 0 Oct 22 17:51 file1
The above example shows the following permissions for the file1 file:
  • user1: read and write
  • group1: read and write
  • everyone else: read
The three main symbols used to represent permissions are rw, and x. These represent read, write, and execute permissions respectively. File permissions are as follows:
  • read: files can be opened and viewed using commands such as cat and less
  • write: edit, save, and delete files
  • execute: allows you to execute the file (files will not be executable unless you also have read permissions)
Permissions for directories are as follows:
  • read: list the contents using the ls command
  • write: edit, save, and delete files within said directory
  • execute: allows you to change into said directory using the cd command. Execute permissions are required to perform a long listing using the ls -l command. Without execute permissions the ls -l command will return output similar to the following:
ls -l test1/
ls: cannot access test1/file1: Permission denied
ls: cannot access test1/file2: Permission denied
total 0
-????????? ? ? ? ?                ? file1
-????????? ? ? ? ?                ? file2
Directory write Permissions 
If a user has write permissions on a directory, that user can remove any file within that directory regardless of file permissions.

The Concept Of umask

The User File Creation Mask or umask value is the bash built-in that defines the default mode for newly created files or directories. The umask value is determined when the effective permissions value of the new files is subtracted from a value of the full file permissions. On Linux systems, full file permissions are:
  • 777 - for directories
  • 666 - for files
The default umask values on Fedora are set in /etc/bashrc. The default umask for user root is 0022 and for regular users (users whose UID is identical to their primary group's GID),umask value is set to 0002. For practical purposes, the first 0 is ignored - it denotes that this value is an octal number. To calculate the default creation mode (effective permissions) of all files and directories created by root user, subtract 022 from the full access mode value of 777 for directories or 666 for files. This means that:
  • new files created by root have permissions set to 644 (666 - 022), or rw-r--r-- in a symbolic denotation
  • new directories created by root have permissions set to 755 (777 - 022), or rwxr-xr-x in a symbolic denotation
Using the same technique, default permissions for files and directories created by normal users are:
  • 664 (666 - 002) or rw-rw-r-- for files
  • 775 (777 - 002) or rwxrwxr-x for directories
User can change this behavior by running umask command with a desired mode as a command argument:
umask 0022
This will cause all new files created by user to have permissions set to 644 and all new directories' permissions set to 755. The change will be in effect until the shell environment is re-initialized. To make permanent changes add umask command to user's ~/.bashrc file. For example, user may wish to have all new files and directories accessible only by himself. In other words, effective permissions on new files should be 600 or rw------- and on new directories 700 or rwx------. To achieve this, add the line:
umask 0077
to the end of ~/.bashrc file, which is the file located under the user's home directory.

Managing Permissions Using The Command Line Interface

Symbolic Method

The following table describes the symbols used to change permissions using the symbolic method. Familiarize yourself with this table before proceeding to the next section:
uthe owner of the file or directory
gthe group the file or directory belongs to
oeveryone else
aeveryone (u, g, and o)
=assign a permission
rread permissions
wwrite permissions
xexecute permissions
tdirectory sticky bit
ssetuid or setgid
To add a permission to a user, group, or everyone else, use the + symbol. The following example adds execute permissions for the owner (u):
chmod u+x file1
To add execute permissions to the owner, and the group, use the following command:
chmod u+x,g+x file1
Please note there is no space between the u+x and g+x. Permissions do not have to be specified separately. The following has the same result as running the chmod u+x,g+x file1 command:
chmod ug+x file1
You must list all permissions needed when you assign permissions using the = symbol. For example, if the owner of the file1 file has read, write, and execute permissions, the follow command removes all but the owners read permissions:
chmod u=r file1
Note, if the group and everyone else had permissions, the previous command would not remove those permissions. You must only list all the permissions if you specify the owner, group, or everyone else when using the chmod command.
Use the - symbol to remove permissions. For example, if the owner of the file1 file had execute permissions, the following command would remove those permissions:
chmod u-x file1

Numeric Method

The following table describes the numbering scheme used when changing permissions using the numeric method:
NumberPermissionsls -l Output
0no permissions---
1execute--x
2write-w-
3write and execute-wx
4readr--
5read and executer-x
6read and writerw-
7read, write, and executerwx
Use the chmod command to change permissions regardless of whether you are using the symbolic or numeric method.
To set permissions using the numeric method, use the chmod xxx command, where xxx are values between 0 and 7. The table above describes the permissions each value (0-7) applies. The first value is the permission for the owner. The second value is for the group, and the third value is for everyone else.
Use the following command to assign the owner read, write, and execute permissions, and remove all permissions for the group and everyone else:
chmod 700 file1
View the permissions using the ls -l command:
ls -l
-rwx------ 1 user1 user1 0 Oct 27 16:02 file1
Use the following command to add read and write permissions for the file1 file for the owner, group, and everyone else:
chmod 666 file1
To change permissions on a folder, and all files and sub-directories within that folder, use the -R option:
chmod -R 700 folder1
This applies mode 700 permissions to the folder1 folder, and recursively changes the permissions of all files and sub-directories within the folder1 folder.

Permissions on Directories

Execute permission on a directory does not allow files within that directory to be executed. Rather, it allows users to change into that directory using the cd command. It also allows user to perform a long listing using ls -l command. However, files within a directory can be executed if said files have execute permissions.

Managing Permissions Using The Graphical User Interface

Follow these steps to access a graphical user interface (GUI) for managing permissions on files and folders:
  • Right click on the file or folder.
  • On the menu that appears, click the Properties menu item.
  • Click the Permissions tab.

Folder Permissions

The following table describes the Folder Access permissions. Changes to Folder Access permissions take immediate effect:
Create and delete filesread, write, and execute
Access filesread and execute
List files onlyread
Noneno permissions, all actions are denied
The following table describes File Access permissions. This allows finer-grained control of files within directories. Changes to File Access permissions take effect only after clicking the Apply permissions to enclosed files button.
Read and writeread and write
Read-onlyread
When the File Access is set to ---, clicking Apply permissions to enclosed files keeps the current file permissions without changing them.
If the Execute: Allow executing file as program box is ticked, execute permissions are applied for everyone to files within that directory. If the Execute: Allow executing file as program box is not ticked, and you click the Apply permissions to enclosed files button, execute permissions are not removed from files within that directory.
If you are a member of a Secondary Group, change the group owner using the Groupdrop-down menu.
File Access Permissions 
After closing and re-opening the properties window for a file or directory, the File Access permissions appear as ---. Your permissions are still set. Use the ls -l [foldername]command to view the file access permissions. If you are already in the [foldername] directory, use the ls -l command.

File Permissions

The following table describes the Access permissions for files. Changes to Access permissions take immediate effect:
Read-onlyread
Read and writeread and write
Noneno permissions, all actions are denied
Ticking the Execute: Allow executing file as program box applies execute permissions for everyone to the file.
If you are a member of a Secondary Group you can change the group owner using the Group drop-down menu.

Special Permissions

There are two special permissions that can be set on executable files: Set User ID (setuid) and Set Group ID (sgid). These permissions allow the file being executed to be executed with the privileges of the owner or the group. For example, if a file was owned by the root user and has the setuid bit set, no matter who executed the file it would always run with root user privileges.

Set User ID (setuid)

You must be the owner of the file or the root user to set the setuid bit. Run the following command to set the setuid bit:
chmod u+s file1
View the permissions using the ls -l command:
ls -l file1
-rwSrw-r-- 1 user1 user1 0 2007-10-29 21:41 file1
Note the capital S. This means there are no execute permissions. Run the following command to add execute permissions to the file1 file, noting the lower case s:
chmod u+x file1
ls -l file1
-rwsrw-r-- 1 user1 user1 0 2007-10-29 21:41 file1
Note the lower case s. This means there are execute permissions.
Alternatively, you can set the setuid bit using the numeric method by prepending a 4 to the mode. For example, to set the setuid bit, read, write, and execute permissions for owner of thefile1 file, run the following command:
chmod 4700 file1

Set Group ID (setgid)

When the Set Group ID bit is set, the executable is run with the authority of the group. For example, if a file was owned by the users group, no matter who executed that file it would always run with the authority of the users group. For example, run the following command as to set the setgid bit on the file1 file:
chmod g+s
Note that both the setuid and setgid bits are set using the s symbol. Alternatively, prepend a 2 to the mode. For example, run the following command as root to set the setgid bit, and read, write, and execute permissions for the owner of the file1 file:
chmod 2700 file1
The setgid is represented the same as the setuid bit, except in the group section of the permissions:
ls -l file1
-rwx--S--- 1 user1 user1 0 2007-10-30 21:40 file1
Use the chmod u+s command to set the setuid bit. Use the chmod g+s command to set the setgid bit.

Special Permissions for Directories

There are two special permissions for directories: the sticky bit and the setgid bit. When the sticky bit is set on a directory, only the root user, the owner of the directory, and the owner of a file can remove files within said directory.

Sticky Bit

An example of the sticky bit is the /tmp directory. Use the ls -ld /tmp command to view the permissions:
ls -ld /tmp
drwxrwxrwt  24 root root  4096 2007-10-30 22:00 tmp
The t at the end symbolizes that the sticky bit is set. A file created in the /tmp directory can only be removed by its owner, or the root user. For example, run the following command to set the sticky bit on the folder1 folder:
chmod a+t folder1
Alternatively, prepend a 1 to the mode of a directory to set the sticky bit:
chmod 1777 folder1
The permissions should be read, write, and execute for the owner, group, and everyone else, on directories that have the sticky bit set. This allows anyone to cd into the directory and create files.

Set Group ID

When the setgid bit is set on a directory, all files created within said directory inherit the group ownership of that directory. For example, the folder1 folder is owned by the user user1, and the group group1:
ls -ld folder1
drwxrwxr-x 2 user1 group1 4096 2007-10-30 22:25 folder1
Files created in the folder1 folder will inherit the group1 group membership:
touch folder1/file1
ls -l folder1/file1
-rw-rw-r-- 1 user1 group1 0 2007-10-30 22:29 folder1/file1
To set the setgid bit on a directory, use the chmod g+s command:
chmod g+s folder1
View the permissions using the ls -ld command, noting the s in the group permissions:
ls -ld folder1
drwxrwsr-x 2 user1 group1 4096 2007-10-30 22:32 folder1
Alternatively, prepend a 2 to the directories mode:
chmod 2770 folder1