Ivorde Unix/Linux/Database/Web/Mail Forum

View unanswered posts
View active topics
It is currently Sat Feb 04, 2012 11:13 pm


News News of Mysql

Site map of Mysql » Forum : Mysql

Mysql Application & Query Optimization, Questions, Indexes, Bugs.

 [ Total topics 15 Go to page 1, 2

Message
 Post subject: Mysql> how to store select Zulu / UTC timestamp in database
PostPosted: Fri Dec 16, 2011 12:23 pm 
To obtain/store the current time in mysql, function "NOW()" needs to be used. But this takes into consideration the timezone set on the server.

To store the UTC time, in the same format, "UTC_TIMESTAMP()" function can be used:

mysql> select now();
+---------------------+
| now() |
+---------------------+
| 2011-12-16 10:19:33 |
+---------------------+
1 row in set (0.00 sec)

mysql> select UTC_TIMESTAMP();
+---------------------+
| UTC_TIMESTAMP() |
+---------------------+
| 2011-12-16 09:19:36 |
+---------------------+
1 row in set (0.05 ...

Read more : Mysql> how to store select Zulu / UTC timestamp in database | Views : 68 | Replies : 0

Top
 Post subject: Mysql> stored procedure for inserting in multiple tables \w common key
PostPosted: Wed Nov 23, 2011 12:15 am 
Below is an example of a mysql stored procedure that:
1) drops the procedure if it already exists
2) creates procedure and defines the fields that it accepts
3) declares an internal variable
4) inserts a row in multiple tables having a common key all tables using last_insert_id() from the first table as their first column's value
5) sets the internal variable to the last_insert_id()
6) selects the internal variable, returning it to the calling ...

Read more : Mysql> stored procedure for inserting in multiple tables \w common key | Views : 186 | Replies : 1

Top
 Post subject: Mysql> select records that have date/datetime column equal to today's date
PostPosted: Tue Nov 22, 2011 4:40 pm 
How to select rows from a mysql table containing multiple records, all of them having a datetime column.

Example mysql table:
Code:
mysql> select * from info;
+---------+---------------------+------------+
| id | upload_date    | ip    |
+---------+---------------------+------------+
|       1 | 2011-11-21 21:07:29 | 0123456789 |
|       2 | 2011-11-21 21:15:07 | 0123456789 |
|       3 | 2011-11-22 14:26:49 | 0123456789 |
+---------+---------------------+------------+
3 rows in set (0.00 sec)


Selecting rows with datetime column equal to today's ...

Read more : Mysql> select records that have date/datetime column equal to today's date | Views : 148 | Replies : 0

Top
 Post subject: How to use a mysql stored procedure
PostPosted: Mon Nov 21, 2011 11:12 pm 
Unlike other sql commands, stored procedures need to be called. Therefore the CALL command needs to be used:

Code:
mysql> CALL stored_procedure_name('argument1,'argument2');

Read more : How to use a mysql stored procedure | Views : 263 | Replies : 1

Top
 Post subject: Mysql command to show stored procedures
PostPosted: Mon Nov 21, 2011 10:57 pm 
Mysql command to show stored procedures

Code:
mysql> show procedure status \G;


or to show stored procedure for a specific database:
Code:
mysql> show procedure status where Db = 'database_name' \G;

Read more : Mysql command to show stored procedures | Views : 162 | Replies : 0

Top
 Post subject: MySql drop unique key/index/constraint
PostPosted: Thu Feb 03, 2011 1:19 am 
To find out what unique indexes are in a table issue:
Code:
mysql> SHOW CREATE TABLE table_name
...
  UNIQUE KEY `unique_user` (`user`),
...


In the above case, there is a unique index / key named 'unique_user' on 'user' column.

To drop the unique key run:
Code:
mysql> ALTER TABLE table_name DROP INDEX unique_user;
Query OK, 6 rows affected (0.05 sec)
Records: 6  Duplicates: 0  Warnings: 0


Read more : MySql drop unique key/index/constraint | Views : 1925 | Replies : 1

Top
 Post subject: MySql rename table
PostPosted: Thu Feb 03, 2011 1:15 am 
To rename a mysql table from old_name to new_name, command is:
Quote:
mysql> RENAME TABLE old_name TO new_name

Read more : MySql rename table | Views : 327 | Replies : 2

Top
 Post subject: Rename MySql table
PostPosted: Sun Aug 22, 2010 12:46 pm 
To rename a mysql table, just use the rename mysql command

Code:
mysql> RENAME TABLE old_name TO new_name;

Read more : Rename MySql table | Views : 462 | Replies : 1

Top
 Post subject: Mysql - Change position of a column after another column
PostPosted: Fri Aug 20, 2010 12:03 pm 
The column order in mysql is not very important in most of the cases, since the SELECT statement can create another column order, one specifically for the application being developed (but not the "SELECT *" statement).

But in cases where order is important, this command will change the position of "column_two" after "column_one".

Code:
mysql> ALTER TABLE table_name MODIFY column_two INT(11) UNSIGNED AFTER column_one;

Read more : Mysql - Change position of a column after another column | Views : 3491 | Replies : 1

Top
 Post subject: Mysql change column's default value
PostPosted: Thu Aug 12, 2010 10:43 am 
Code:
mysql> ALTER TABLE table_name MODIFY column_name INT DEFAULT 'some default value';


Remember that column type must be a char, varchar, enum or some other column type that supports default value. TEXT/BLOB columns do NOT support default values.

If an attempt to set a text column's default value a mysql error will be produced:
Quote:
ERROR 1101 (42000): BLOB/TEXT column 'preferences' can't have a default value

Read more : Mysql change column's default value | Views : 1470 | Replies : 0

Top
 [ Total topics 15 Go to page 1, 2


Last 10 active topics


Apache, Nginx, Lighttpd and other web server software

No new posts Nginx + php-fpm setting php upload_max_filesize and other php values per vhost
View the latest post

Mysql

No new posts Mysql> how to store select Zulu / UTC timestamp in database
View the latest post

TCP/IP Networking

No new posts Quagga ospf neighbour stuck in ExStart/DROther state
View the latest post

FTP, Scp, Sftp, Rsync

No new posts How to disable anonymous access in samba 3
View the latest post

Package and Software Management

No new posts "checking for libnet_build_ip in -lnet... no"+"ERROR! Libnet library not found"
View the latest post

Server and Network Security

No new posts CentOS Install Nemesis packet crafting tool + Libnet
View the latest post

Tutorials for general Unix

No new posts Using curl to get the HTTP response from an HTTP server
View the latest post
No new posts Linux - Unable to login (and authentication succeeds) - File size limit exceeded
View the latest post
No new posts Linux/FreeBSD how to check ntp time synchronization
View the latest post

Memory, Storage, Backup and Filesystems

No new posts Mdadm - Linux software RAID
View the latest post

Login

Username:   Password:   Log me on automatically each visit  

Statistics

Statistics

Total posts 188 | Total topics 681 | Total members 811



cronNews News Site map Site map SitemapIndex SitemapIndex RSS Feed RSS Feed Channel list Channel list


Delete all board cookies | The team | All times are UTC + 2 hours [ DST ]

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
DAJ Glass 2 template created by Dustin Baccetti

phpBB SEO