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..

February 4th, 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 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..

January 25th, 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..

December 11th, 2011 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..

November 27th, 2011 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 : 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..

November 1st, 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

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..

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

AddThis Social Bookmark Button

Mysql Tricks : Show status information on a table

Show status information on a table. Note, if the database was started with --safe-show-database or --skip-show-database some of these commands may not work. Note the "\G" option may provide a nicer format. Show the create statement: mysql> show create table dupTest\G ... Read more..

May 17th, 2011 admin Posted in MySQL No Comments »

AddThis Social Bookmark Button

Dump Content using mysqldump

You do not need to enter mysql for this , here is the exact sintax you must use : mysqldump -u [username] -p [database_name] > /path/to/file.sql  example mysqldump -u mario  -p marioDB > /tmp/marioDB.sql Read more..

May 2nd, 2011 admin Posted in MySQL No Comments »

AddThis Social Bookmark Button

Recovering / Changing Your MySQL Root Password

Recovering / Changing Your MySQL Root Password Sometimes you may have to recover the MySQL root password because it was either forgotten or misplaced. The steps you need are: 1) Stop MySQL [root@bigboy tmp]# service mysqld stop Stopping MySQL:  [  OK  ] [root@bigboy tmp]# 2) Start MySQL in Safe mode with the mysqld_safe command and tell it not to read the grant tables with all the MySQL database passwords. [root@bigboy tmp]# mysqld_safe --skip-grant-tables --skip-networking & [1] 13007 [root@bigboy tmp]# Starting mysqld daemon with databases from /var/lib/mysql [root@bigboy tmp]# Note: In Fedora ... Read more..

April 6th, 2011 admin Posted in MySQL No Comments »

AddThis Social Bookmark Button


Page 1 of 212