mysql

designing mySql index and primary keying for efficiency

I have a mid-size collection of records --about 20 million -- that I need to load into mySQL for use in data analysis. These happen to be records of people visiting places. They are uniquely identified by three data items: place - a unique INT person - a character string, sometimes numeric and sometimes alphanumeric , eg AB123456...

measuring performance - using real clicks vs "ab" command

I have a web site in closed beta, developed in Django, runs with Mysql on Debian. In the last few days, the main page has been showing a slowdown. For every ten clicks, one or two receives extremely slow response (10 secs or more), others are as fast as they used to be. When I was searching for the problem, I ran into this issue that ...

How can I use LIKE with an arbitrary word order in MySQL?

I need to use the LIKE keyword or some other similar operator for this purpose: In the database, the name and surname is stored as one column and it's in the order surname name (e.g. "Doe John"). I have a search bar with lets you enter your name and surname. When I am going to search, I require that if you enter name surname instead of...

mysql - some form of union needed

in mysql, if i have a query that returns something like b-2; c-4, e-9 is there a way i could unite it with a-0; b-0; c-0; d-0; e-0; f-0; to get a final result a0; b-2; c-4; d-0; e-9, f-0? i understand that the better way to approach it is to rewrite the original query, but it is somewhat complex for my level (complete sql noob), a...

Escaping user data, without magic quotes

Hey, I'm taking a look at how to properly escape data that comes from the outside world before it gets used either for application control, storage, logic.. that kind of thing. Obviously, with the magic quotes directive being deprecated shortly in php 5.3.0+, and removed in php6, this becomes more pressing, for anyone looking to upgrad...

Reset primary key in mysql?

Hi all; In my table tbphotos i had 100 recordes then i deleted all,now that i want restart data entry i see that my primary key doesn't start from 1 , but it start from 101 ,is there any way? -I work in "Mysql administrator" thanks ...

What to avoid in php/mysql/ajax when relying on heavy reads/writes

Hi, i was wondering what the main things were to avoid when creating an webapplication that relies on heavy reads and writes every second. Think of online gaming where money is involved. For example you have an javascript that constantly updates the browser(1), There is a cronjob running that updates the db(2), There is user input subm...

CREATE SCHEMA gives 1064 error

CREATE SCHEMA IF NOT EXISTS `paragraph` DEFAULT CHARACTER SET 'utf8' COLLATE default collation ; this line results with error 1064. MySql 5.4.3-beta. ...

md5 for emails too?

I'm creating a MySQL database with registered users, and I'm thinking to use md5 not only for passwords but for e-mails too. I think this choice can improve user security, but I'm not yet an expert with databases and I'm not sure if this is wise or not! I hope this isn't a stupid question! ...

How can I check if mysql table column even exists ?

How can I check if mysql table field even exists ? The column name is 'price' and I need to see if it exists. Haven't understood really how the 'EXISTS' works... Any examples or ideas ? Thanks ...

Left JOIN faster or Inner Join faster?

So... which one is faster (NULl value is not an issue), and are indexed. SELECT * FROM A JOIN B b ON b.id = a.id JOIN C c ON c.id = b.id WHERE A.id = '12345' Using Left Joins: SELECT * FROM A LEFT JOIN B ON B.id=A.bid LEFT JOIN C ON C.id=B.cid WHERE A.id = '12345' Here is the actual query Here it is.. both return the same...

MySQL: add created and modified fields

What's the best approach to add created and modified fields in MySQL: 1) using MySQL features like on update CURRENT_TIMESTAMP or 2) using PHP (or something else)? Why? If the answer is MySQL, how would you do this? Thank you! ...

What is MySQL primary (key1, key2)

I am working on existing DB and try to optimize it. I see a table without a single primary key but with two foreign keys work as a primary key. I know it will work. however, is it better to have one single primary key with two foreign keys for better performance or primary (key1, key2) will just work as good as one? For example: CREA...

Why does my python script randomly get killed?

Basically, i have a list of 30,000 URLs. The script goes through the URLs and downloads them (with a 3 second delay in between). And then it stores the HTML in a database. And it loops and loops... Why does it randomly get "Killed."? I didn't touch anything. Edit: this happens on 3 of my linux machines. The machines are on a Rackspac...

Sorting by unknown column type in mysql

So I've got a users table; storing things like username, email, etc. I then have a user_settings table. Instead of standard columns like timestamp_logged_in, profile_views, etc., I have it organized as key/value combo. For example, the columns are: user_settings_ID user_ID name value A sample record would be: 82 2 'timestamp_logged_in'...

PHP/MySQL last edit script?

How do I create a php script that stores and displays when an article was last edited using PHP and MySQL. ...

PHP / MYSQL: Sanitizing user input - is this a bad idea?

I have one "go" script that fetches any other script requested and this is what I wrote to sanitize user input: foreach ($_REQUEST as $key => $value){ if (get_magic_quotes_gpc()) $_REQUEST[$key] = mysql_real_escape_string(stripslashes($value)); else $_REQUEST[$key] = mysql_real_escape_string($value); } I haven't seen anyone el...

PHP - UPLOAD_ERR_NO_TMP_DIR

I am using Cbeyond (www.cbeyond.com, some of you might be familiar with them) as a PHP Enabled webhost, I'm having issues with my PHP Upload functions, when I check as follows: $error = $_FILES['uploadedfile']['error']; echo $error; I get "6", for the error message: "UPLOAD_ERR_NO_TMP_DIR" I have a /tmp directory at my root, here i...

Insert Groups of Rows with PHP & MYSQL

I'm trying to load data from a few hundred text files into a database. I believe MYSQL is exiting out of the loop without inserting all the rows. Can anyone suggest how to insert blocks of 1000 rows to the end of data, with PHP code? $filenames_array = array(); foreach($filenames_array as $filename) { $file_array = file($fi...

MySQL databse speed question?

Is it alright to have many tables inside a database or should I create another database. If so what it the limit on how many tables I should have in a database? Will having many tables in a database affect the speed of the database? ...