MySQL Import Command

by Tweak on January 10, 2012
in Mysql

How do I import data stored in a “.sql” file (created by mysqldump command) under UNIX or Linux operating systems?

The syntax is as follows to import the data created by mysqldump command:

mysql -u{DB-USER-NAME} -p{DB-PASSWORD} {DB-NAME} < {db.file.sql}
mysql -h{MySQL-SERVER-HOST-NAME} -u{DB-USER-NAME} -p{DB-PASSWORD} {DB-NAME} < {db.file.sql}

In this example import a file called sales.sql for salesdb1 user and sales db, enter:
$ mysql -u123tweak -p123password 123tweak < 123tweak.sql
Read more…

CentOS / Red Hat IPv6 Network Configuration

by Tweak on April 22, 2011
in Linux, Servers

Setting up IPv6 on CentOS, and for that matter RHEL and Fedora Linux, is quite straight forward. You need to edit just two files:

1. /etc/sysconfig/network-scripts/ifcfg-
2. /etc/sysconfig/network

  1. Configure the IP address. For example, for interface eth0, edit /etc/sysconfig/network-scripts/ifcfg-eth0 and make the necessary changes as below.DEVICE=eth0
    HWADDR=00:22:15:17:CC:C1
    BOOTPROTO=static
    IPADDR=192.168.1.2
    NETMASK=255.255.255.0
    NETWORK=192.168.1.0
    BROADCAST=192.168.1.255
    IPV6INIT=yes
    IPV6_AUTOCONF=no
    IPV6ADDR=<ipv6 address>
    ONBOOT=yes
  2. Read more…

Reset MySQL root Password

by Tweak on April 22, 2011
in Mysql

To reset MySQL root user’s password, follow the following steps.

  1. Terminate all running instances of MySQL server. You can do that either via the RC script (/etc/init.d/<script_name> stop or /user/local/etc/rc.d/<script_name> stop for FreeBSD) or using the tools like kill and pkill. To use kill or pkill, you will have to use ps or pgrep to find out the process names or process ID (PID).

    Using the RC script to do a proper shutdown is safer than using kill or pkill.

  2. Start the MySQL server in safe modemysqld_safe --skip-grant-tables --user=mysql
  3. On another terminal, login to the MySQL server as the root usermysql -u root
    Read more…

Turn on MySQL query cache to speed up query performance?

by Tweak on April 20, 2011
in Mysql

Many times developers looking for ways to speed up query, in mysql we can enable query cache to speed up query performance. Whenever query cache is enable, it will cache the query in memory and boost query performance.

As we know, speed is always the most important element in developing a website especially for those high traffic database driven website. You can try to turn on query cache to speed up query.

To speed up query, enable the MySQL query cache, before that you need to set few variables in mysql configuration file (usually is /etc/my.cnf or my.ini)

- 1st, set query_cache_type to 1. (There are 3 possible settings: 0 (disable / off), 1 (enable / on) and 2 (on demand).

query-cache-type = 1
Read more…

How to find large files in Linux

by Tweak on April 20, 2011
in Linux

At the command line as root enter:

find / -size +102400k

This will find all files on the entire system that are bigger than 100 MB.

Use this one to see the sizes:

find / -size +103400k | xargs ls -laAh

Use “find .” to look only in the current directory.

find . -size +103400k | xargs ls -laAh
Read more…

Schedule tasks on Linux using crontab

by Tweak on April 14, 2011
in Ajax, Linux, Servers

If you’ve got a website that’s heavy on your web server, you might want to run some processes like generating thumbnails or enriching data in the background. This way it can not interfere with the user interface. Linux has a great program for this called cron. It allows tasks to be automatically run in the background at regular intervals. You could also use it to automatically create backups, synchronize files, schedule updates, and much more. Welcome to the wonderful world of crontab.

Crontab

The crontab (cron derives from chronos, Greek for time; tab stands for table) command, found in Unix and Unix-like operating systems, is used to schedule commands to be executed periodically. To see what crontabs are currently running on your system, you can open a terminal and run:

sudo crontab -l

To edit the list of cronjobs you can run:

sudo crontab -e

This wil open a the default editor (could be nano or pico, if you want you can change the default editor) to let us manipulate the crontab. If you save and exit the editor, all your cronjobs are saved into crontab. Cronjobs are written in the following format:

* * * * * /bin/execute/schedulescript.sh
Read more…

Change the default editor Linux

by Tweak on April 1, 2011
in Linux

Ever wanted to change the crontab of a server, but got an editor on screen that you’re totally unfamiliar with? There are a lot of causes for this annoyance, but one is that somebody recently installed or used midnight commander (mc) which for whatever reason seams to overrule your session’s default editor.

Changing the editor

The first time it took me a while to figure it out so I thought lets make it an article on my site, so maybe it will help others save some time.

Anyhow, here how to change it, just open your terminal and type

export EDITOR="nano"

nano can be nano, pico, vim, or another text editor of your choice of course.
Read more…

Backup MySQL in command line with compression

by Tweak on March 30, 2011
in Mysql

For those who looking for way to backup mysql database,
you can use mysqldump to backup mysql database.

Below is the script example to backup mysql database in command line:-

$ mysqldump -h localhost -u username -p password database_name > backup_db.sql

If your mysql database is very big, you might want to compress your sql file.
Just use the mysql backup command below and pipe the output to gzip,
then you will get the output as gzip file.
Read more…

How to install MySQL on CentOS Redhat Linux

by Tweak on February 16, 2011
in Linux, Mysql

Install MySQL with YUM
yum install mysql-server mysql php-mysql

How to configure MySQL Read more…

Optimizing a php application in 5 minutes

by Tweak on November 24, 2010
in Php

It is often said that premature optimization is the root of all evil: it is indeed true that the optimization stage must come after the main development of an application has been completed. Optimizing means reducing loading and execution times, improving the user experience by making the application reacting more responsively.
When it comes the time to optimize your web application, don’t go blindly searching for the bottleneck. Often there are no obvious improvable points in a codebase and your assumptions about the slowness causes can be wrong. Profiling is the activity of discovering what is forcing your application run slower than expected, by analyzing the code execution and time tracking.
If your language of choice is php, fortunately this process takes only 5 minutes.
Read more…

Next Page »