Take MySql database Backups remotely from command line

If you are a developer it is obvious that you take frequent backups of the project you develop.  If you are a web developer chances are that you always login to cpanel or some other dashboard provided by your hosting provider to take backups. Some tools provide scheduled backups on server.  This is fine if database is small. But if database is big or if you have many databases , this process gonna take large amount of space on your server. To free space you need to download to your computer and delete remote backups.

If you are this stage and you are searching for better alternative this is the one line command that can save you some time.

 

You can take help of scheduler on your computer to take periodic backups of the database on store them on your computer. This way you can save lot of time. remote MySql need to be enabled in few hosts for this scripts to work. Also if mysql environment variable is not set you need to navigate to that folder and run command for this to work.

WordPress: server error

If you try to move wordpress sites between servers you may experience this issue.

HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request.

I had no idea what causing this. It was working fine with the other server. After a lot of debugging and googling I understood this error might be because PHP memory limit. So I tried to increase memory limit. Again as there are couple ways to increase this variable and not all hosts allow all of them I had to face some issues.  below are the possible ways to increase PHP memory limit and get rid of this error to make your site work again.

 

1. php.ini

By changing following variable you can increase emory limit value in php.ini

But chances are that you might be n shared hosting and your hosting provider might not allow you to make any changes directl to php.ini. In that case you can set this in .htaccess or in run time using ini_set variable.

Above is the .htaccess way of increasing memory limit.  Again some hosts wont allow you to set PHP variables using .htaccess . In this case you may experience Internal server error as those lines code in .htaccess would be treated as invalid. In that case you can change memory limit value using ini_set like below. You can also set a wordpress constant WP_MEMORY_LIMIT in wp-config.php and this is better way.

 

 

Cakephp 2.x Auth Component : Change password

Changing password of any user is easy if you are using Auth Component. I have been Using Auth Component for many of my projects developed in Cakephp.  Below are the steps for password change functionality of Auth component in CakePHP 2.x.
Create a new function called pass() in the controller .( users controller in my case )
( you can  name the function anything. )

 

Setting user Id is important here or a new record is created every time you try to change password. You can either pass id through query params or you can get it from Auth. In the above example User Id is taken from Auth.
 Now create a view file with function name in the views/{controller_name}/ directory. In this case it would be views/Users/pass.ctp
Create a form to change password in that view file

 

As we are not redirecting to other method or controller . it is suggested to show message so user can know password is changed. 

Now comes the magic in the model. We are asking for current password. And if that is correct we are going to check if both new passwords match. If they match change password and display message.
to the $validate array in your model add this 

 

 So we need to create two functions one for checking current password and other to check if both passwords matches or not.

Magento : get product details

I am working on my first Magento project . I’d say it is not a CMS you would master in a day or two , especially if you are used to work on very well documented CMSs that have good support like WordPress , Drupal. In my project I want to get product details on the product view page. I want to show product details like Product name, description , short description , Price , Special price etc. If you are working on Magento for the first time chances are that you tweak by copying base template files into your package rather than theming from scratch. I learnt it is indeed a good practice unless you need a whole different design or structure.  Well if you are tweaking existing file and you are wondering how to get different product details , here are the ones you should look for.

 

 

Mysql database administration tutorial – User management

Users in MySQL can be created in two ways. First way is by using CREATE or GRANT statements. Second one is to update or add to ‘user’, ‘grant’ tables of MySQL database (MySQL database is default databases that comes with installation and it holds important data realated to users, privilages and othe databases)

Using CREATE USER and GRANT statements:

Priviliges can be limited by specifying in GRANT statement. for eg GRANT SELECT, INSERT, UPDATE ON database.* TO ‘username’@'hostname’ IDENTIFIED BY password;

Maximum number of queries , updates , connections can also be decided usind Grant statement. for eg:- if you feel that a user is abusing resources and you want to limit user connections and no of connections perhour, updates, queries, You can limit it by the following statement.

Revoking privileges

User privileges can be revoked by REVOKE statement.
For eg:-

similarily there are Statements to rename user and set a password for user.
for eg: -

 

Creating user by inserting values in mysql database

User can be created using simple insert commands

If you want limit or provide any privileges look for colomn in the user table and update ‘Y’ to provide and ‘N’ to revoke privileges. Also there are columns max_questions,max_updates,max_connections and max_user_connections to restrict resources to a user.  We can use simple UPDATE , DELETE DML statements on user to modify user data in mysql.user table

Mysql database administration tutorial – Introduction

MySQL, an open source software is a relational database management system.SQL is the most common standardized language used to access databases and is defined by the ANSI/ISO SQL Standard. Current version of the standard is “SQL:2003”

Main features of Mysql are

  • Written in C and C++.
  • Tested with a broad range of different compilers.
  • Works on many different platforms.
  • Designed to be fully multi-threaded using kernel threads, to easily use multiple CPUs if they are available
  • Provides transactional and nontransactional storage engines.
  • Implements in-memory hash tables, which are used as temporary tables.
  • Works in cross platform.
  • supports stored procedure, functions, triggers, views, subqueries and partitioning.
  • Supports replication and clustering for High Availability.

Architecture

Mysql architecture is divided into two levels

1. Application layer
2. Logical Layer

Application layer

This is the layer where users, clients connect to Mysql server to query data. there are three components in this layer

  1. admin interface Like mysqladmin, isamchk etc
  2. Client Interfaces . For eg various Mysql APIs like PHP API
  3. Query interface for users to interact with server using ‘mysql’

Logical Layer

Logical layer is further divided into subsystems.

Query processor
All the D*L statements sent from application layer are parsed and optimized in this Query processing layer
Transaction management
This is where transaction management is sone in mysql .A transaction is a single unit of work that has one or more MySQL commands in it. The transaction manager is responsible for making sure that the transaction is logged and executed atomically.It also executes commit and rollback to revert the transactions

  • Ensures Atomicity
  • Avoids Deadlocks
  • Responsible for Commit & Rollback

Recovery management
Recovery management is to retrive and rollback database to its previous state if necessary. It is done by using logs of system. There are different variables one can tune in configuration settings to configure logs and use them to recover to old state
Storage management
Ultimately storage of data is physically done on some secondary storage like hard disks. But dynamic access of medium is done by mainating some buffers in the main memory. These buffers reciding in main and virtual memory is maintained by buffer manager , which is part of storage manager.

 

Mysql Database administration tutorial

MySQL!  A well known and most popular open source database system needs no introduction to any programmer. MySQL database administration skills are often required by number of programmers and web application developers. This tutorial is targeted for application developers who either wants to improve their administration skills in MySQL or to optimize MySQL database to improve performance of application. This is also targeted to novice MySQL database administrators who wants to improve their knowledge or fill knowledge gaps. It is not the purpose of this tutorial to serve as documentation or complete reference. Please refer MySQL website for complete reference and documentation.

Here is the complete list of topics that are covered in this tutorial.

  1. Introduction,features
  2. MySQL start up scripts
  3. User management
  4. Storage Engines
  5. MySQL client and utility Programs
  6. Server variables
  7. Server Logs
  8. Backup and recovery
  9. Multiple MySQL installations on single computer
  10. Optimization
  11. Buffering and caching
  12. MySQL default databases (information schema, MySQL)
  13. Replication
  14. Conclusion