Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6859937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:20:45+00:00 2026-05-27T02:20:45+00:00

I need to create a table in MySQL version 5.5 this table will have

  • 0

I need to create a table in MySQL version 5.5

this table will have information like:

  • user browsers (Firefox or chrome for example)
  • version of the browser (eg: 8.0 or 10)
  • IP of the user
  • date and time (when the user accessed the site)
  • referrer (URL or empty)

Here’s what i think:

create table statistics (
 browser varchar(255) not null,
 version float not null,
 ip varchar(40) not null,
 dateandtime datetime,
 referrer varchar(255)
);

I read on mysql.com that I need to use indexes to make my query fast but now my problem is what index should I create in order to make that table fast to query?

I need to query all the fields eg:

  • I want to know from the last 7 days which browser came to our site and how many
  • I want to know today how many user I have
  • I want to know from the last hour what urls (referrer) we got

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:20:46+00:00Added an answer on May 27, 2026 at 2:20 am

    I would recommend this:

    Use intergers instead of chars/varchars. this way you index faster (except the referrer). Also, I can recommend to get summary tables. Although it’s not really normalized but the query will be executed instantly – specially if you have a big organization with lots of traffic.

    So here’s the tables:

    create table statistics (
     browser tinyint(3) UNSIGNED not null default 0,
     version float(4,2) not null default 0,
     ip INT(10) UNSIGNED not null default 0,
     createdon datetime,
     referrer varchar(5000),
     key browserdate (browser, createdon),
     key ipdate (ip, createdon),
     // etc..
    );
    

    browser 0 = unknow, 1 = firefox etc.. This can be done in your code (so you load the same code for inserting and selecting). i dont use enum here because if you need to alter the table and you have millions of records this can be painful. new browser = new number in the code which is way faster to change.

    this table can be used to resummarized all the other tables if something happens. so you create an index for the inline summary table (example browser)

    Now the summary table:

    create table statistics_browser_2011_11 (
     browser tinyint(3) UNSIGNED not null default 0,
     version float(4,2) not null default 0,
     number bigint(20) not null default 0,
     createdon datetime,
     unique key browserinfo (createdon, browser, version)
    ); // browsers stats for november 2011
    

    This way when you inserts (you get the date of the user when he accessed the site and create a $string that match with the table name) into this table you only have to use the on duplicate key number = number +1. this way when you retrieve the browser statistics is super fast.

    now here you will have to create a merge table because if you are the second of the month and you want to query the last 7 days, you will need the current month and the last month table. here’s more info: http://dev.mysql.com/doc/refman/5.1/en/merge-storage-engine.html

    and you repeat the process for the other information: ip, referrer etc…

    in order to maintain these tables, you will have to create a cronjob that creates tables for the next month. simple PHP script that gets the current year/month and then create the table for the next month if it does not exists and then merge them)

    this might be a little of work but this is how i do it at work (with similar data) with 12 terabytes of data and 5,000 employees that fetch the databases. my average load time for each query is approx 0.60 seconds per requests.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to create a table in MySQL that will have indexes for each
I have a MySQL table like this CREATE TABLE IF NOT EXISTS `vals` (
Suppose I have a simple MySQL table that looks like this: CREATE TABLE `my_table`
I have downloaded the MySQL 5.2.5.1 version. I need to create the database and
I need to create a table in MySQL which stores the different currency symbols
I have a MySQL table consisting of: CREATE TABLE `url_list` ( `id` int(10) unsigned
I have an MySQL table: CREATE TABLE responses ( id INT NOT NULL AUTO_INCREMENT,
I need to create a database table to store different changelog/auditing (when something was
I would need to create a temp table for paging purposes. I would be
I need to create an SQL query to insert some data into a table

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.