mysql

What's the easiest way to import a new table into MySQL v5 from CSV?

I'm running MySQL 5 on a linux server on my local network. Running windows XP for my desktop. Had a look at the MySQL GUI Tools but I dont think they help. I cannot install apache on the remote server & use something like PHPmyAdmin. ...

Problem joining on the highest value in mysql table

I have a products table... and a revisions table, which is supposed to track changes to product info I try to query the database for all products, with their most recent revision... select * from `products` as `p` left join `revisions` as `r` on `r`.`product_id` = `p`.`product_id` group by `p`.`product_id` order by `r`.`modified` ...

How do I install MySQL modules within PHP?

I've updated php.ini and moved php_mysql.dll as explained in steps 6 and 8 here. I get this error Fatal error: Call to undefined function mysql_connect() in C:\inetpub... MySQL doesn't show up in my phpinfo; report. I've updated the c:\Windows\php.ini file from ; Directory in which the loadable extensions (modules) reside. exten...

What is the ideal data type to use when storing latitude / longitudes in a MySQL database?

Bearing in mind that I'll be performing calculations on lat / long pairs, what datatype is best suited for use with a MySQL database? ...

How do I loop through a MySQL query via PDO in PHP?

I'm slowly moving all of my LAMP websites from mysql_ functions to PDO functions and I've hit my first brick wall. I don't know how to loop through results with a parameter. I am fine with the following: foreach ($database->query("SELECT * FROM widgets") as $results) { echo $results["widget_name"]; } However if I want to do somet...

What does mysql error 1025 (HY000): Error on rename of './foo' (errorno: 150) mean?

I tried this in mysql: mysql> alter table region drop column country_id; And got this: ERROR 1025 (HY000): Error on rename of './product/#sql-14ae_81' to './product/region' (errno: 150) Any ideas? Foreign key stuff? ...

Why ActiveRecord instead of a MySql API

I've been developing web applications for a while and i am quite comfortable with mySql, in fact as many do i use some form of SQL almost every day. I like the syntax and a have zero problems writing queries or optimizing my tables. I have enjoyed this mysql api. The thing that has been bugging me is Ruby on Rails uses ActiveRecord an...

Does this query look optimized?

I'm writing a query for an application that needs to list all the products with the number of times they have been purchased. I came up with this and it works, but I am not too sure how optimized it is. My SQL is really rusty due to my heavy usage of ORM's, But in this case a query is a much more elegant solution. Can you spot anything...

MySQL server goes away in XAMPP

Hello, I am trying to install xampp 1.6.7 in a Red Hat Enterprise Edition. I followed the installation instructions and after that I started the stack with the command sudo /opt/lampp/lampp start And I get te usual response XAMPP: Starting Apache with SSL (and PHP5)... XAMPP: Starting MySQL... XAMPP: Starting ProFTPD... XAMPP for L...

MySQL Query: LIMITing a JOIN

Say I have two tables I want to join. Categories: id name ---------- 1 Cars 2 Games 3 Pencils And items: id categoryid itemname --------------------------- 1 1 Ford 2 1 BMW 3 1 VW 4 2 Tetris 5 2 Pong 6 3 Foobar Pencil Factory I want a...

Error Updating a record

I get a mysql error: #update (ActiveRecord::StatementInvalid) "Mysql::Error: #HY000Got error 139 from storage engine: When trying to update a text field on a record with a string of length 1429 characters, any ideas on how to track down the problem? Below is the stacktrace. from /var/www/releases/20081002155111/vendor/rails/activere...

Database Design Issues with relationships

I'm working on an upgrade for an existing database that was designed without any of the code to implement the design being considered. Now I've hit a brick wall in terms of implementing the database design in code. I'm certain whether its a problem with the design of the database or if I'm simply not seeing the correct solution on how to...

Converting a UNION query in MySQL

Hi All, I have a very large table (8gb) with information about files, and i need to run a report against it that would would look something like this: (select * from fs_walk_scan where file_path like '\\\\server1\\groot$\\%' order by file_size desc limit 0,30) UNION ALL (select * from fs_walk_scan where file_path like '\\\\server1\\hro...

Versioning a MySQL database when code base doesn't have a ORM

I've been thinking about this problem for a while and have yet to come up with any stable/elegant ideas. I know with MyISAM tables, you can get the table def update time but thats not so true with InnoDB and I've found its not even reliable to look at the .frm file for an idea of when the definition might have been modified.... nevermin...

How to enable STRICT_ALL_TABLES' for single MySQL database?

Is there a way to enable STRICT_ALL_TABLES for a single MySQL database? ...

How to find out if a certain value exists as a primary key in mySql?

What is the best way to find out if a primary key with a certain value already exists in a table? I can think of: SELECT key FROM table WHERE key = 'value'; and count the results, or: SELECT SQL_CALC_FOUND_ROWS key FROM table WHERE key = 'value' LIMIT 1; SELECT FOUND_ROWS(); ...

CHAR() or VARCHAR() as primary key in an ISAM mySQL table?

I need a simple table with a user name and password field in mySQL. Since user names must be unique, it makes sense to me to make them the primary key. Is it better to use CHAR() or VARCHAR() as a primary key? ...

Easy mysql question regarding primary keys and an insert

In mysql, how do I get the primary key used for an insert operation, when it is autoincrementing. Basically, i want the new autoincremented value to be returned when the statement completes. Thanks! ...

What's quicker; including another file or querying a MySQL database in PHP?

In PHP, which is quicker; using include('somefile.php') or querying a MySQL database with a simple SELECT query to get the same information? For example, say you had a JavaScript autocomplete search field which needed 3,000 terms to match against. Is it quicker to read those terms in from another file using include or to read them from ...

SQL Query which returns a table where each row represents a date in a given range

Is it possible to create a SQL query which will return one column which contains the dates from a given date range (e.g. all dates from last year till today). E.g. dat ---- 2007-10-01 2007-10-02 2007-10-03 2007-10-04 ... I am wondering if this is possible as an alternative to creating a table which holds all those dates precalculated....