mysql

MySQL 5.1 command line problem: delete last char doesn't work

I can't delete the last character in a given line in the MySQL CLI, if I press "END", it will jump on the character and if I press "DEL", it will delete the char before that (like backspace). Does anybody know a fix for that issue? I use MySQL 5.1.31-1ubuntu2-log with normal shell access. Thank you for assistance! ...

MySQL: Add sequence column based on another field

Hi all, I'm working on some legacy code/database, and need to add a field to the database which will record a sequence number related to that (foreign) id. Example table data (current): ID ACCOUNT some_other_stuff 1 1 ... 2 1 ... 3 1 ... 4 2 ... 5 2 ......

How to export 20 000 contacts from MySQL database via PHP for import into an desktop address book?

Hello, I need to write a script to export contact data for printing on stickers for mailing. There could be up to 20 000 records in the database table. The main problem is that the number of records could be so high and the site is hosted on a shared server and exporting the whole 20k records would, presumably, kill the script or stall....

mysqldump and wamp

Update: Finally got this thing working but still not sure what the problem was. I am using a wamp server that I access through a networked folder. The problem that still exists is that to execute the mysqldump I have to access the php file from the actual machine that is being used to host the WAMP server. End of update I am running a...

SQL/MySQL structure (Denormalize or keep relational)

I have a question about best practices related to de-normalization or table hierarchy relationships. For a simple example, let's say I have an app that allows a user to make a payment for an order. I save the order information in the orders table, and I have another table for the payment called payments. Payments has a foreign key to th...

Zend Form Field Mapping To DB Columns

I have a Zend_Form $form = new My_Form(); $uploadedData = $form->getValues(); Zend_Debug::dump($uploadedData, $form->name,true) and when i dump the form values i get a string array array(11) { ["event"] => string(2) "26" ["firstname"] => string(3) "sdf" ["surname"] => string(0) "" ["gender"] => string(1) "M" ["company"] => ...

MySQL conditional SELECT statement

If there are records that have a field containing "X", return them, else return a random record. How the heck do you do this? ...

Make a Copy of Live MySQL database periodically

Hi Friends, I am stuck with a problem. I am working on a backoffice project which needs to access the live database of our website which is very big and complicated. Now when i connect my backoffice with live Mysql database and run my queries, some slow queries are also there which in turn locks the database for that time period and the...

Related posts: Get records by tags from different tables

Hi, I'm working on a news site. Like every news site there will be news, columns, videos and photo galleries. I'm planning to keep these different types of records in different tables but relate them with tags. Here is a simple schema: Tables: News, Videos, Galleries, Columns, Tags, Post_to_tags Post_to_tags: - tagid - postid - posttyp...

categories off-set

Hi there, I am about to build an SQL database and i need to get it right instead of making mistakes and fixing them down the line which is why i am here... I will have main categories and sub categories to them, i need to know weather it'd be best to store the sub categories in the same tables as the main but just offset them for exam...

How can I SELECT 16 records at random from a range of rows in MySQL?

I want to display a list of 16 of the most popular items in my database, but I want that list to be different every time. So from say, the top 50 downloaded items, choose 16 at random and return that in the result. Is that possible with just one query? ...

What's the easiest way to add an index on a live myISAM table?

I have a myISAM table running in production on mySQL, and by doing a few tests, we've found we can tremendously speed up a query by adding a certain compound index. So far so good. However, I am not really about the best way to add this index in a production environment without locking the table for a long time (it's got 27GBs of data, s...

MySQL - Join Based on Date

Is it possible to join two tables based on the same date, not factoring in time? Something like: ...FROM appointments LEFT JOIN sales ON appointments.date = sales.date... The only problem is it is a datetime field, so I want to make sure it is only looking at the date and ignoring time ...

JDBC, MySQL: getting bits into a BIT(M!=1) column

I'm new to using JDBC + MySQL. I have several 1/0 values which I want to stick into a database with a PreparedStatement. The destination column is a BIT(M!=1). I'm unclear on which of the setXXX methods to use. I can find the references for what data comes out as easily enough, but how it goes in is eluding me. The values effectivel...

Randomly selecting a limited number of records with two conditions in MySQL

I have a MySQL table with a column called "priority". The column can have two values: high or low. I want to select 8 records from the table at random, but I want 6 of them to be high priority, and 2 of them to be low priority. If possibly, I would like to do it in one SQL statement. Is there any way to do two LIMITS in one query bas...

Using MySQL user-defined variable in stored procedure for 'in' clause

When sending a string of comma separated ids, as a varchar, to a MySQL stored procedure I can not use the string as part of an IN clause with the correct results returned. The string is truncated as a decimal and only the first value is being used. I thought I would be able to get around this by preparing and then executing the statemen...

Why Does My MySQL Query Using a Subselect Hang?

The following query hangs: (although subqueries perfomed separately are fine) I don't know how to make the explain table look ok. If someone tells me, I'll clean it up. select sum(grades.points)) as p, from assignments left join grades using (assignmentID) where gradeID IN (select grades.gradeID from assignments left join grade...

PHP Loop Question?

I have a php script that will loop until all the skill, exp and rating variables are displayed that the user entered into the database. What I want is the following code to only display once and only if the variables are holding info and not empty. How can I do this. I hope I explained it okay. I want this code displayed first. echo '...

is there sql notation that can tell check between months?

I'm storing recurring events in an events table that take place during certain months of the year, any year and every year. For instance; CREATE TABLE events ( event_id tinyint(3) unsigned NOT NULL auto_increment, name varchar(255) NOT NULL, month_from tinyint(3) unsigned NOT NULL, month_to tinyint(3) unsigned NOT NULL, P...

Rails with in memory database

Can I set rails to use mysql with MEMORY as the DB engine? I never restart mysql, and rebuild the db so often I'd rather have it be fast. Having the memory db for running tests would be nice too. EDIT: I should have specified this is for dev/testing only, not production. ...