Rename or change name of MySQL table

This is how to change the name of an existing table tableone to tabletwo : RENAME TABLE  tableone TO tabletwo;  Note : you must issue this command with an user that has the correct priviledges Read more..

May 11th, 2012 admin Posted in MySQL No Comments »

AddThis Social Bookmark Button

Mysql Tricks : Print defaults for the current client connection

Print defaults for the current client connection $ my_print_defaults client mysql --port=3306 --socket=/tmp/mysql.sock --no-auto-rehash Note, for client connections, you can put setting in the user's .my.cnf file. ... Read more..

April 28th, 2012 admin Posted in MySQL No Comments »

AddThis Social Bookmark Button

MySQL dump import -> Error 1217

If you use  innodb tables and foreign key constraints, importing a mysqldump may generate foreign key errors. To resolve this issue please read on : At the beginning of the dump file add this : SET FOREIGN_KEY_CHECKS=0; At the end of the dump file add this : SET FOREIGN_KEY_CHECKS=1; This will disable foreign key checks for the mysqldump import session only. This will allow the data to be imported without the error being generated. Read more..

April 25th, 2012 admin Posted in MySQL No Comments »

AddThis Social Bookmark Button

Mysql Tricks : Find out who is doing what, and kill the process if needed.

Find out who is doing what, and kill the process if needed. This example kills Id 657. mysql> show processlist; show processlist; +-----+------+-----------+---------+---------+-------+-------+------------------+ | Id | User | Host | db | Command | Time | State | Info | ... Read more..

April 18th, 2012 admin Posted in MySQL No Comments »

AddThis Social Bookmark Button

Delete a column from an existing MySQL table

This is how to delete the column my_thing from the table your_table ,  (use the following SQL command: ) ALTER TABLE 'your_table' DROP 'my_thing' enjoy Read more..

April 5th, 2012 admin Posted in MySQL No Comments »

AddThis Social Bookmark Button

Increment an exisitng value in Mysql

To increment or decrement and existing number in a table (you do not need to read the value first)  please read on : Increment the value 'timer' by one for the row in table 'movies' where 'movie_id' is '24', use: UPDATE movies SET timer=timer+1 WHERE movie_id=24 Note  to decrement use timer=timer-1 Enjoy Read more..

March 27th, 2012 admin Posted in MySQL No Comments »

AddThis Social Bookmark Button

Display a list of databases on a MySQL server

This is how to list the databases that exist in a MySQL server, use the 'show databases' SQL command: show databases; +------------------+ | Database                | +------------------+ | database1              | | mysql                     | | test                         | +------------------+ It will display all the databases your user has access to Read more..

March 25th, 2012 admin Posted in MySQL No Comments »

AddThis Social Bookmark Button

Change max_allowed_packet setting fast

If you want to change the  max_allowed_packet fast, without modifying any confis or restart mysql ? Follow this howto : mysql> show variables like 'max%' ; +-----------------------+------------+ | Variable_name | Value | +-----------------------+------------+ | max_allowed_packet | 1048576 | ... mysql> set max_allowed_packet = 1500000; Query OK, 0 rows affected (0.03 sec) mysql> show variables like 'max%' ; +-----------------------+------------+ | Variable_name | Value ... Read more..

March 20th, 2012 admin Posted in MySQL No Comments »

AddThis Social Bookmark Button

Mysql Tricks : error 1016

"error: 1016: Can't open file:" If it's from an orphaned file, not in the database but on disk, then, the disk file may need to be deleted. myisamchk can help with damaged files. It's best to stop the database. # su - # mysqladmin shutdown ... Read more..

February 19th, 2012 admin Posted in MySQL No Comments »

AddThis Social Bookmark Button

Drop or delete a table in MySQL

This is how to remove a table from a MySQL database, and remove all of its data, use the following SQL command: 1.  log in mysql 2.  issue command : use yourdatabase;  3. issue command : drop table if exists yourtable; The last command will delete the database if it exists , it is usefull because if it does not exist it will not output any error Read more..

January 31st, 2012 admin Posted in MySQL No Comments »

AddThis Social Bookmark Button

Mysql Tricks : Clean up binary log files

Clean up binary log files. For a default install they may be in /usr/local/var/ or /var/lib/mysql/ with names ending in -bin.000001,-bin.000002,.. The following command may help find out where the logs are located. mysql> show variables like '%home%'; ... Read more..

November 25th, 2011 admin Posted in MySQL No Comments »

AddThis Social Bookmark Button

MySQL Replace Function

MySQL Replace(), here's the syntax. update [table_name] set [field_name] = replace([field_name],'[string_to_find]','[string_to_replace]'); Read more..

November 5th, 2011 admin Posted in MySQL No Comments »

AddThis Social Bookmark Button

Mysql Tricks : MERGE: Several tables can be merged into one

MERGE: Several tables can be merged into one. CREATE TABLE log_01 ( pkey int(11) NOT NULL auto_increment, a int, b varchar(12), timeEnter timestamp(14), ... Read more..

October 23rd, 2011 admin Posted in MySQL No Comments »

AddThis Social Bookmark Button

Create a basic MySQL table

Creating tables in databases is the  first step to store your data To create a table you must describe the columns and their atributes. We will create a table to hold contact information with four columns: contact_id, name, email, and birthdate. contact_id column =  integer number that is 20 decimal places long ( it is created with an INT(20) datatype). name column holds the full name of a contact, which we  will will set be no longer than 50 characters long, so the ... Read more..

October 21st, 2011 admin Posted in MySQL No Comments »

AddThis Social Bookmark Button

Mysql Tricks : Transactions

Transactions: Not all table types support transactions. BDB and INNODB type do support transactions. Assuming the server has NOT been started with --skip-bdb or --skip-innodb the following should work: mysql> create table tran_test (a int, b int) type = InnoDB; mysql> begin; mysql> insert into tran_test (a,b) values (1,2); ... Read more..

October 9th, 2011 admin Posted in MySQL No Comments »

AddThis Social Bookmark Button

Import CSV file directly into MySQL

You can use mysql to import directly a csv file . You do not need to make a script to do this anymore From an Excel file , you need to export it as CSV ,  Remove the CSV Headers and the Excel data  from the file ,  and after that it can be inserted in MySql Here is an example : load data local infile 'your.csv' into table tblUniq fields terminated by ',' enclosed by '"' lines terminated by '\n' (yourName, yourCity, yourComments) Read more..

October 4th, 2011 admin Posted in MySQL No Comments »

AddThis Social Bookmark Button

Mysql Tricks : Can the order of the columns in a create statement make a difference?

Can the order of the columns in a create statement make a difference? YES create table t ( a int, b int, timeUpdate timestamp, timeEnter timestamp ); The first timestamp will always be the "automatically ... Read more..

August 24th, 2011 admin Posted in MySQL No Comments »

AddThis Social Bookmark Button

Mysql Tricks : Quick Status

Quick Status: mysql> \s -------------- /usr/local/bin/mysql Ver 14.3 Distrib 4.1.1-alpha, for pc-linux (i686) Connection id: 642 Current database: Current user: prog@localhost SSL: ... Read more..

August 21st, 2011 admin Posted in MySQL No Comments »

AddThis Social Bookmark Button

Mysql Tricks : Remove duplicate entries

Remove duplicate entries. Assume the following table and data. CREATE TABLE IF NOT EXISTS dupTest ( pkey int(11) NOT NULL auto_increment, a int, ... Read more..

August 1st, 2011 admin Posted in MySQL No Comments »

AddThis Social Bookmark Button

Show or list tables in a MySQL database

First step is to select a database , after that you can view the tables  1 . view all of the tables in the selected database : SHOW TABLES; 2.  view all of the tables in a different database (not selected): SHOW TABLES IN different_db; 3.  view a specific table in the selected  database : SHOW TABLES IN newDB LIKE '%time'; The above command will find all tables that end in "time"  from the database newDB Read more..

June 8th, 2011 admin Posted in MySQL No Comments »

AddThis Social Bookmark Button


Page 1 of 212