Pages

Monday, February 29, 2016

MySQL

What is MySql ?

 

Its a fast and easy to use Relational Database Management System(RDBMS) being used for many small and large scale businesses.

Database is an application that stores a collection of data. Nowadays we mostly use RDBMS to store and manage large volumes of data. This is called Relational Database, since all data are stored in tables and and different tables are related using relations like primary keys or foreign keys.

 

 


Installing MySQL Using binaries

 

  •  First download the required package as a tar file
  • Then uncompress it at the place where you desire to make the mysql installation directory

  • Execute the following commands creating a user and a group called mysql


shell> groupadd mysql
shell> useradd -r -g mysql -s /bin/false mysql
shell> cd /usr/local
shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz
shell> ln -s full-path-to-mysql-VERSION-OS mysql
shell> cd mysql
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> scripts/mysql_install_db --user=mysql
shell> chown -R root .
shell> chown -R mysql data
shell> bin/mysqld_safe --user=mysql &

  • here I chose /usr/local as my installation directory 
  • Be careful when giving permissions to the created mysql user as the root


 Problem...?

Above mentioned steps didn't make my mysql demaen up. terminal struck in  the middle
the below error was given when the service was tried to started

test@hsenid-OptiPlex-3020:/usr/local/mysql$ service mysql.server start
Failed to start mysql.server.service: Unit mysql.server.service failed to load: No such file or directory.

 

      Solution :)

what is mysqld...?

http://dev.mysql.com/doc/refman/5.7/en/mysqld.html


it is the main program that does all the work in the mysql installation process.

it manages access to MySql data data directory which stores mysql databases and tables and also log files and status files.

Then I found that there are several methods of starting the mysql server

  1. invoking mysqld directly
  2.  invoking mysqld_safe which tries to determine proper options for mysqld http://dev.mysql.com/doc/refman/5.7/en/mysqld-safe.htmlOn linux systems that support systemd, can use it to control the server
  3. http://dev.mysql.com/doc/refman/5.7/en/server-management-using-systemd.html
  4.  On systems that uses System V-style run directories (such systems provides a standard process for controlling which programs init launches and configuration files for SysV init are located in the /etc/rc.d/ directory.) invoke mysql.server  http://dev.mysql.com/doc/refman/5.7/en/mysql-server.html



  • I used the last method. 
  • There I implemented the final steps

shell> cp mysql.server /etc/init.d/mysql
shell> chmod +x /etc/init.d/mysql

  • then move to etc folder

shell> cd /etc
shell> ln -s rc.d/init.d   //this didn't work for me sice I had init.d file directly in etc
                             so,create a symbolic link pointing to rc.d/init.d to init.d
                              
 
  • Now the system is installed. It is needed to activate it. Use following in linux
 
 
 
shell> chkconfig --add mysql
 
if required...
 
shell> chkconfig --level 345 mysql on 


 update-rc.d mysql default  => to start


  • Then run mysql

 bin/mysql -u root -p
 


  • following might be a useful link

http://coolestguidesontheplanet.com/start-stop-mysql-from-the-command-line-terminal-osx-linux/ 


MySQL from the Command Line


  • to see whether mysql runs properly 
 test@hsenid-OptiPlex-3020:~$ sudo netstat -tap | grep mysql

tcp6       0      0 [::]:mysql              [::]:*                  LISTEN      813/mysql

  • securing mysql accounts

https://dev.mysql.com/doc/refman/5.6/en/default-privileges.html


  • check the status of mysql service 

/etc/init.d/mysql.server status

service mysql.server status

  • Configure MySQL to launch at any place without going to the bin directory 

add the following to  the bashrc file

MYSQL_HOME=/usr/local/mysql
export PATH=$JAVA_HOME/bin:$ANT_HOME/bin:$MAVEN_HOME/bin:$CATALINA_HOME/bin:$MONGODB_HOME/bin:$MYSQL_HOME/bin:$PATH


and source the bash file 

  •  Find the port, hostname & username of mysql 

start mysql

mysql> select user();
+--------+
| user() |
+--------+
| test@  |
+--------+



mysql> SHOW VARIABLES WHERE Variable_name = 'port';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port          | 3306  |
+---------------+-------+
1 row in set (0.00 sec)


mysql> SHOW VARIABLES WHERE Variable_name = 'hostname';
+---------------+--------+
| Variable_name | Value  |
+---------------+--------+
| hostname      | hsenid |
+---------------+--------+
1 row in set (0.00 sec)

 

  • To change the port in mysql

    check the chosen port is pure =>  sudo netstat -tanp| grep 3337


     Edit etc/mysql/my.cnf file  

 MySQL GUI Tools

  •  Workbench => suitable(current version 6.3)Navicat for Mysql

  • Sequel Pro => suitable (comes with 5 extra languages)

  • HeidiSQL => proj discontinuied since 2010

  • SQLyog => only Windows

  • SQL Wave => 30 day trial version

  • dbForge Studio

  • MyDB studio

 





 

 

 

 








 


 

Thursday, February 25, 2016

Markdown


What is MArkdown....??


   MArkdown is a text to HTML conversion tool.  It allows to write the text on a easy to read and easy to write plain text with some defined syntax and the text would be converted to a structurally valid HTML page. 



In this blog post we are discussing markdown syntax for plain text formatting 


The below screen shot would provide an idea of it.




In the above figure, the first column shows the markdown syntax, while the second column is the corresponding HTML format. The display on the browser is shown in the third column.

 NOTE If you can't do something in markdown, then you can easily switch back and forth between Markdown and HTML within one document


Markdown Syntax

 

 

 

 

 

 

 

 




.Md Files

 

The files written with Markdown syntax are saved on .md files

Markdown formatted documents or .md files are publishable as it is (plain text)

.Md files are not only useful as an easy replacement for HTML documentation, but also for source code version control systems like GitHub. The reason for this is that files can be compared with historical versions.  

A file called README.md is present in GitHub, popular version control system, which contains details if the project (how to install the program, how to use its functions and basically what it does) , written in markdown syntax




 




References

 https://www.shopify.com/partners/blog/86763270-what-is-markdown-syntax

Sunday, February 14, 2016

Unix Editors

  The Vi Editor

 

The vi editor is a screen editor which is available in Unix systems. It has no means, but instead uses an order of combinations of key strokes to accomplish commands. Thus it can be known as a program that can be used to create and modify files.   

 

Starting vi

      To start using vi, at the Unix prompt type vi followed by the filename


% vi filename

In this way you can either open an already existing file or create a new file. Once you press Enter, you'll be shown with blank lines with tildes and the name and status of the file

 

 

Vi Modes

Vi has two modes. Knowing the mode you are working at a given time is essential. The two modes are


  1.  Command mode

    letters in the keyboard will be interpreted as commands. vi always starts out in command mode. To leave the insert mode you are in, hit ESC key

  2.  Insert mode 

      letters in keyboard will type or edit text. Hit i to enter this mode.

        

    Entering Text

    First change to insert mode by typing the letter i. Hit Enter at the end of each line. If you make a mistake, use Backspace key to remove the error. In case it doesn't work properly on your system, use Ctrl + h combination.

     

    Cursor Movement

     To move the cursor to another position of your file, you must be in Command mode

     


  3.  

     Basic Editing

     To issue editing commands, one should be in Command mode. Uppercase, Lowercase affects for the interpretation of the command

     




    Closing and Saving files

     When we are editing a file in vi, we are actually editing a copy of the file rather than the original

     

     

     

      The Vim Editor

     

    Vim is the contracted form of "Vi Improved". It is actually an improved version of the Vi editor distributed with most Unix systems. Vim is a free and an open source software.  

     

    Vim is designed to be used both from Command Line Interface and Graphical User Interface. The GUI mode of Vim is gvim. It has menues and toolbars for the commonly used commands. But its full functionality is achieved through the Command Line Interface.   

     

    In summary Vim can be considered as the superset of Vi. Thus everything explained in Vi is included in Vim too with some added features like : 

     

    1.   Is compatible with much wider range of OS's than Vi.

    2.   Supportive for several programming languages like Perl, pyhton, C/C++

    3.     Scan edit files inside a compressed crchive(zip, tar, gzip etc)

    4.   Ability to edit multiple files.

    5.    Can be used to edit files using network protocols like HTTP etc.

    6.   Support scripting languages like vimscript, perl, python

    7.    Includes builtin diff for comparing files  

    8.   Includes multilevel undo/redo


        

       

      Emacs  Editor 

        GNU Emacs is a free, customizable and extensible text editor. It is also portable and runs under many operating systems. The main ones are :


       A especial feature of emacs is that we can not only customize all its usage like font, color, mousage, menus, windows etc, but also we can program emacs to perform totally new things. Emacs does more than a typical editor. It is designed as a programmers' editor. Some general functionalities of emacs are :
     
    • It provides an 'edit mode' , which enables to edit the code together with the context sensitive facility

    • It allows to compile the written code within emacs 

    • Can debug the program within emacs and provides links to the source  

    • Interact directly with the language interpretor  when appropriate

    • Interact with the revision control system

    •  Manage change logs

    •  Also provide other necessities for programming like mail readers, news readers, World Wide Web, spell checkers,FTP clients etc

       

    How to install... ??

      1. First download the GNU Emacs latest version which is available as a tar file. You can use the following site. 

        https://www.gnu.org/software/emacs/

      2.  Unzip the tar file using the command 

        $ tar -zxvf emacs-24.5.tar.gz 

      3. Then open the uncompressed folder using the command 

        cd emacs-24.5

      4.        Open the INSTALL file in it using vi editor and can follow the      instructions given
        

       

      Problems Encountered.......

      • When ./configure was run an error popped proposing the remedy as to add  '--without-x'. Thus  ./configure  --without-x was typed

      • Above step in turn gave an error as libtinfo, libncurses, libterminfo, libtermcap, libcurses packages were missing and asked to install at least one of them. 

      • When tried to install above packages warning came as unable to locate packages. After google search the below solution worked for me

      sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu $(lsb_release -sc) main universe"
      sudo apt-get update
      sudo apt-get install libncurses5-dev
       
      •       Afterwards  mentioned procedure was carried out from ./configure  --without-x