Logo Background RSS

» Mysql

  • Copying a Table
    By on March 4th, 2009 | 1 Comment1 Comment Comments

    /*create a copy of a table so that you
    can alter it or experiment with it without endangering the original
    data
    */

    CREATE TABLE new_table_name
    SELECT * FROM old_table_name;

    /* Differences: their names,
    if the old table had an index (or key), it
    does not transfer to the new table.
    only two columns chosen
    */

  • Restart Mysql from ssh
    By on February 10th, 2009 | 1 Comment1 Comment Comments

    To restart mysql service from command line (ssh)

    * Login to SSH as root using a program like putty.
    * Type the following command,

    /scripts/restartsrv_mysql

    Hope you all enjoy this command.

  • Enable caching in MySQL
    By on February 2nd, 2009 | 1 Comment1 Comment Comments

    Log into your mysql

    $ mysql -u root –p

    Output:

    Enter password:

    Welcome to the MySQL monitor. Commands end with ; or \g.

    Your MySQL connection id is 16 to server version: 4.1.15-Debian_1-log
    Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

    mysql>

    Now setup cache size 32Mb:
    mysql> SET GLOBAL query_cache_size = 33554432;    
    
    Query OK, 0 rows affected (0.00 sec)
    mysql> SHOW VARIABLES LIKE 'query_cache_size';

    Output:

    +——————+———-+

    | Variable_name | Value |

    +——————+———-+

    | query_cache_size | 16777216 |

    +——————+———-+

    You can setup them in /etc/my.cnf (Red Hat) or /etc/mysql/my.cnf (Debian) file:
    # vi /etc/my.cnf
    Append config directives as follows:

    query_cache_size = 33554432
    query_cache_type=1
    query_cache_limit=2096576
    
                    
  • Restoring The Database via SSH
    By on February 1st, 2009 | 3 Comments3 Comments Comments

    Restoring The Database via SSH

    Login with ssh on your hosting server.

    then goto mysql

    mysql -u dbusername -p databasename < backupname.sql

    • dbusername => Your database user name
    • databasename => Your Database name
    • backupname.sql (with full path where your sql file present)
    • then hit enter
    • it will ask your password of database
    • then click enter

    If your hosting company has you on a remote MySQL server, such as mysql.yourhost.com, you will need to add the servername to the command line. The servername will be the same as in your config.php. The command line will be:

    mysql -h servername -u dbusername -p databasename < backupname.sql

    Or:

    mysql -h servername -u dbusername -p databasename < /path/to/backupname.sql

    Now you guys have any difficulty post your comments here :)

  • Change MySQL data default directory
    By on October 30th, 2008 | 1 Comment1 Comment Comments

    MySQL is a widely used and fast SQL database server. It is a client/server implementation that consists of a server daemon (mysqld) and many different client programs/libraries.

    If you want to install Mysql Database Server in Ubuntu check this tutorial.

    What is Mysql Data Directory?

    Mysql data directory is important part where all the mysql Databases storage location.By default MySQL data default directory located in /var/lib/mysql.If you are running out of space in /var partition you need to move this to some other location.

    Note:- This is only for advanced users and before moving default directory make a backup of your mysal databases.

    Procedure to follow

    Open the terminal

    First you need to Stop MySql using the following command

    sudo /etc/init.d/mysql stop

    Now Copy the existing data directory (default located in /var/lib/mysql) using the following command

    sudo cp -R -p /var/lib/mysql /path/to/new/datadir

    All you need are the data files, so delete the others with the command

    sudo rm /path/to/new/datadir

    Note:- You will get a message about not being able to delete some directories, but that’s what you want.

    Now edit the MySQL configuration file with the following command

    gksu gedit /etc/mysql/my.cnf

    Look for the entry for “datadir”, and change the path (which should be “/var/lib/mysql”) to the new data directory.

    Important Note:-From Ubuntu 7.10 (Gutsy Gibbon) forward, Ubuntu uses some security software called AppArmor that specifies the areas of your filesystem applications are allowed to access. Unless you modify the AppArmor profile for MySQL, you’ll never be able to restart MySQL with the new datadir location.

    In the terminal, enter the command

    sudo gedit /etc/apparmor.d/usr.sbin.mysqld

    Copy the lines beginning with “/var/lib/mysql”, comment out the originals with hash marks (”#”), and paste the lines below the originals.

    Now change “/var/lib/mysql” in the two new lines with “/path/to/new/datadir”. Save and close the file.

    Restart the AppArmor profiles with the command

    sudo /etc/init.d/apparmor reload

    Restart MySQL with the command

    sudo /etc/init.d/mysql restart

    Now MySQL should start with no errors, and your data will be stored in the new data directory location.

  • Install Mysql Database Server with Phpmyadmin Frontend
    By on October 30th, 2008 | No Comments Comments

    MySQL is a widely used and fast SQL database server. It is a client/server implementation that consists of a server daemon (mysqld) and many different client programs/libraries.

    Installing Mysql database in Ubuntu

    sudo aptitude install mysql-server mysql-client libmysqlclient15-dev

    This will complete the installation of mysql server 5.0.45 in ubuntu gutsy.

    Configuring Mysql in ubuntu

    MySQL initially only allows connections from the localhost (127.0.0.1). We’ll need to remove that restriction if you wish to make it accessible to everyone on the internet. Open the file /etc/mysql/my.cnf

    sudo gedit /etc/mysql/my.cnf

    Find the line bind-address = 127.0.0.1 and comment it out

    #bind-address = 127.0.0.1

    You can check your configuration using the following command

    #netstat -tap

    Output Looks like below

    tcp 0 0 *:mysql *:* LISTEN 4997/mysqld

    MySQL comes with no root password as default. This is a huge security risk. You’ll need to set one. So that the local computer gets root access as well, you’ll need to set a password for that too. The local-machine-name is the name of the computer you’re working on. For more information see here

    sudo mysqladmin -u root password your-new-password

    sudo mysqladmin -h root@local-machine-name -u root -p password your-new-password

    sudo /etc/init.d/mysql restart

    Manage Mysql using Phpmyadmin

    phpMyAdmin is a tool written in PHP intended to handle the administration of MySQL over the Web. Currently it can create and drop databases, create/drop/alter tables, delete/edit/add fields, execute any SQL statement, manage keys on fields, manage privileges,export data into various formats and is available in 54 languages. GPL License information.

    Install phpmyadmin in ubuntu

    sudo aptitude install phpmyadmin

    This will complete the installation.

    Now you need to goto http://serverip/phpmyadmin/

    Login using your mysql root as username and password