[mysql] MySQL: How to set the Primary Key on phpMyAdmin?

Help! First time using phpMyAdmin. The column that I intend to set as a primary key is of TEXT in phpMyAdmin, it gave me an error message, the primary key can't be set! And I don't want to change it to INT. How can I solve this? Million thanks!

PS. I haven't input any values or relate any other tables on this table yet.

The screen cap

This question is related to mysql phpmyadmin

The answer is


You can set a primary key on a text column. In phpMyAdmin, display the Structure of your table, click on Indexes, then ask to create the index on one column. Then choose PRIMARY, pick your TEXT column, but you have to put a length big enough so that its unique.


MySQL can index the first x characters of a column,but a TEXT type is of variable length so mysql cant assure the uniqueness of the column.If you still want text column,use VARCHAR.


You can view the INDEXES column below where you find a default PRIMARY KEY is set. If it is not set or you want to set any other variable as a PRIMARY KEY then , there is a dialog box below to create an index which asks for a column number ,either way you can create a new one or edit an existing one.The existing one shows up a edit button whee you can go and edit it and you're done save it and you are ready to go


You can't set the field having data-type "text". Only because of that thing you are getting this error. Try to change the data-type with int


Examples related to mysql

Implement specialization in ER diagram How to post query parameters with Axios? PHP with MySQL 8.0+ error: The server requested authentication method unknown to the client Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver' phpMyAdmin - Error > Incorrect format parameter? Authentication plugin 'caching_sha2_password' is not supported How to resolve Unable to load authentication plugin 'caching_sha2_password' issue Connection Java-MySql : Public Key Retrieval is not allowed How to grant all privileges to root user in MySQL 8.0 MySQL 8.0 - Client does not support authentication protocol requested by server; consider upgrading MySQL client

Examples related to phpmyadmin

phpMyAdmin on MySQL 8.0 phpmyadmin - count(): Parameter must be an array or an object that implements Countable Error loading MySQLdb Module 'Did you install mysqlclient or MySQL-python?' phpMyAdmin ERROR: mysqli_real_connect(): (HY000/1045): Access denied for user 'pma'@'localhost' (using password: NO) phpMyAdmin access denied for user 'root'@'localhost' (using password: NO) mysqli_real_connect(): (HY000/2002): No such file or directory How to create a foreign key in phpmyadmin #1292 - Incorrect date value: '0000-00-00' MySQL error - #1932 - Table 'phpmyadmin.pma user config' doesn't exist in engine phpMyAdmin Error: The mbstring extension is missing. Please check your PHP configuration