The MySQL documentation isn't very clear on this. I want to add an index to an existing table. The table is a user table with the login id and password and I want to create an index for this to optimize logging in.
This is how I thought I would try it:
mysql> ALTER TABLE `users` ADD INDEX(`name`,`password`);
This created:
mysql> show index from karmerd.users;
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment |
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| users | 0 | PRIMARY | 1 | id | A | 2 | NULL | NULL | | BTREE | |
| users | 1 | name | 1 | name | A | 2 | NULL | NULL | | BTREE | |
| users | 1 | name | 2 | password | A | 2 | NULL | NULL | YES | BTREE | |
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
Did this achieve what I was trying to do? (Optimize logging in?) Previously I only had a primary key on an a field called 'id'.