mysql

Is there any legitimate reason for using Unix sockets over TCP/IP with mysql?

I'm trying to figure out why mysql uses Unix socket (/tmp/mysql.sock) by default, instead of normal TCP/IP sockets. It doesn't seem like a security thing, as you can listen only on 127.0.0.1 which should be equally safe (socket file is world-writable, so you don't get Unix accounts based protection). And surely all operating systems re...

Mysql character set and collation value change.

Hi. I have a table temp. I applied new character set and collation in MYSQL with following query: ALTER TABLE temp CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin; Now I want to revert this back to what the table was before I changed the attributes. Is there a way I can do that? Thanks for help in advance. ...

Hibernate problems with Auto Increment ID MYSQL 5

So, I just stood up a Spring Hibernate app and I can't seem to get my mapping file right. I am using MySql 5 and an auto incrementing key. Here is the ID portion of my mapping file. <hibernate-mapping> <class name="org.XXXXXXX.Contact" table="contact"> <id name="id" column="id" type="int" unsaved-value="null"> <...

Database Tables, more the better?

Lately I've been rethinking a database design I made a couple of months ago. The main reason is that last night I read the databse schema of vBulletin and saw that they use many, MANY, tables. The current "idea" I'm using for my schema, for instance my log table, is to keep everything in one table by differencing the type of Log with an...

PHP image creation from hex values in database

I've got the code below to pull hex values from a database and create an image of that colour. There's over a thousand values, so it's looping to create an image for them all. It seems to work fine except it just keeps overwriting the first image (0.jpg) instead of creating new ones 0.jpg, 1.jpg 2.jpg etc. Any idea where I'm going wrong?...

How To Store Tags In A Database Using MySQL and PHP?

I wanted to create a database that will store the tags that users enter for there questions and then display them all for each individual question posted something like here on SO. Here is the table that does everything for me know. CREATE TABLE questions_tags ( id INT UNSIGNED NOT NULL AUTO_INCREMENT, url TEXT NOT NULL, tag VARCHAR(25...

MYSQL IF(expr1,expr2,expr3) but I don’t want any expr3 (if expr3 then don’t output anything.

As the title says, I just want an output if the if is matched, if it’s not matched then I don’t want any output. I currently have this, but it gives an error obviously ...rFormat=IF(ISNULL(rFormat), VALUES(rFormat),UNCHANGED)… I looked around http://dev.mysql.com/doc/refman/5.4/en/control-flow-functions.html but didn’t really find ou...

MySQL join with LIMIT 1 from two tables

I have two tables. One with information about properties. The other stores 3 images for each property. Of these three images - one is marked as being the "main" image. So I have: Properties: p_id name 1 villa a 2 villa b 3 villa c 4 villa d and Images i_id p_id main 1 1 0 2 1 0 3 1 1 4 2 0 ...

Select surrounding rows php/mysql

I want to select a group of rows around a row matched on conditions, ie select a row and then return 5 records before and after it. More info as requested (sorry bout that!) Ok, so the table records lap times from a race. Laps are related to Users (users have many laps). I want to find the best lap time for a User then x number of best...

Is this a case for denormalisation?

I have a site with about 30,000 members to which I'm adding a functionality that involves sending a random message from a pool of 40 possible messages. Members can never receive the same message twice. One table contains the 40 messages and another table maps the many-to-many relationship between messages and members. A cron script run...

Php - Insert Autoincrement Value - For Parent/Child Tables - Concurrency Problem

Consider a simple schema of one to many relationship. Parent Table's Id is referenced in the Child table. In php I want to insert a row into the table using the statement mysql_query($query). Then I will get the id of the last inserted row by using mysql_insert_id(). Then i will use this id to insert the another row into the child's tab...

Externalized time dimension in MySQL OLAP cubes?

It appears to be a common practice to let the time dimension of OLAP cubes be in a table of its own, like the other dimensions. My question is: why? I simply don't see what the advantage would be to have a time_dimension table of (int, timestamp) that is joined with the cube on some time_id foreign key, instead of having a timestamp co...

UTF-8, and mbstring extension in php

While I was converting my latin-1 mysql database into utf-8 i came across this article (http://developer.loftdigital.com/blog/php-utf-8-cheatsheet) please note I have successfully converted my database and my app appears to be working/outputting correctly It the previously mentioned link it says about installing and using the mbstring ...

Portable SQL that works in SQL Server, mySQL and postgreSQL

Hello, Am wondering if there are guidelines somewhere to write SQL code which is compatible in SQL Server, mySQL as well as postgreSQL. I am writing a program and the user has a choice of backend database. It will be really difficult for me to create separate queries for each and every db. I do not want to use an ORM or anything like th...

MySql setting that allows "" to be equal to null or 0?

I've got a MySQL server running on linux and another on Windows, both containing duplicate copies of a database table. The table is defined like: parent_id - int(10) - nullable - default=null title - varchar(100) I can execute this sql on Linux, and it works fine (I know, it's wrong and horrible and shouldn't work, but it does). Inser...

how to implement a double join in n-to-n relation in MySQL

In my database I have cars and persons. Between the cars and the persons is an n-to-n 'drives'-'is driven by' relationship. I would like to query the database to get a list of all the cars that are driven by a specific person (say 'john') and that are also driven by other persons. I would like the query to show per car how many (other) ...

Changing character sets

How do I edit the character set file (latin1.xml in my example)? http://thenoyes.com/littlenoise/?p=91 I tried to follow the steps mentioned on the page above, but did not get the full text working as expected. ...

mysql union statement with order by

Hi all, I'am trying to understand what causes the following, maybe you could help me: I have a query like: select field1,fieldDate from table1 union all select field1,fieldDate from table2 order by fieldDate desc and the another one like this: select field1,field2,fieldDate from table1 union all select field1,field2,fiel...

Mysql multiple tables select

I've got a table, called for example, "node", from which i need to return values for as shown: SELECT nid FROM node WHERE type = "book" After i get a list of values let's say: |**nid**| |123| |12451| |562| |536| Then I need to take these values, and check another table, for rows where column 'path' has values as "node/123", "node/1...

mysql/php - How to implementing a unique view system?

Introduction I am wondering what is the best way to implement a unique views system... I think I know how, so if I could explain how I think to do it and you point out any mistakes or improvements. obviously I will have to store a log table containing a video id and something which (relatively) uniquely identifies the user. At first I ...