Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding Index to column in mysql [closed]

How do I create an index with PHPmyadmin?

I have a database with 5,000 rows of

ID | IP | DATE

Before added data to this table I made id as Primary Key,

The website use this query:

mysql_query("SELECT * FROM users WHERE ip = '$ip'");

I read today that indexes can speed up and performance, and in my case how do i need to add index to IP column,

I am to phpmyadmin and to actions I see "Add unique index" and "Add index" options, Im new in this, appreciate your help, thank you.

like image 905
Albi Hoti Avatar asked Jan 19 '13 21:01

Albi Hoti


2 Answers

Click on the icon that says "index" in the row for ip. (It's the one with the lightening bolt). Don't choose primary key or unique. Just index.

like image 170
John Conde Avatar answered Sep 29 '22 12:09

John Conde


Or you can run a query:

ALTER TABLE `users` ADD INDEX `ip` (`ip`)
like image 38
Viacheslav Kondratiuk Avatar answered Sep 29 '22 11:09

Viacheslav Kondratiuk