LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-28-2017, 11:34 AM   #1
qajaq
Member
 
Registered: Sep 2008
Location: north-central Florida
Distribution: Lubuntu 19.04, Kubuntu 18.04
Posts: 119

Rep: Reputation: 15
MySQL fails to set auto_increment start value > 1


I've created a database and table ("sesame") in MySQL and populated it with 55 pre-existing values from a former spreadsheet. Now I'm writing a PHP script that will allow additions to the table in the future. I have a field ("id") to hold a unique identifier for each record. The existing records have "id" values from 1 to 55, so I want future additions to start the auto_incrementing from 56.

But when I give the following command from the MySQL CLI
Code:
ALTER TABLE sesame MODIFY COLUMN id SMALLINT UNSIGNED PRIMARY KEY AUTO_INCREMENT = 56;
I get an error message that tells me to look for the "right syntax to use near '= 56' at line 1".

I've tried various permutations of the MODIFY TABLE command, but keep getting error messages. Any ideas what I should be using?
 
Old 04-28-2017, 01:03 PM   #2
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 20 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918
As far as I am aware, you apply the initial auto-increment value to the whole table once you have defined the auto increment column.

So:
Code:
ALTER TABLE sesame MODIFY COLUMN id SMALLINT UNSIGNED PRIMARY KEY AUTO_INCREMENT;

ALTER TABLE sesame AUTO_INCREMENT = 56;
 
1 members found this post helpful.
Old 04-28-2017, 01:08 PM   #3
qajaq
Member
 
Registered: Sep 2008
Location: north-central Florida
Distribution: Lubuntu 19.04, Kubuntu 18.04
Posts: 119

Original Poster
Rep: Reputation: 15
Thank you, hydrurga! That worked. Other sites I'd found included a reference to the column name, so I had never thought to try it without that.
 
Old 04-28-2017, 01:10 PM   #4
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 20 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918
Quote:
Originally Posted by qajaq View Post
Thank you, hydrurga! That worked. Other sites I'd found included a reference to the column name, so I had never thought to try it without that.
My pleasure, qajaq.
 
  


Reply

Tags
incrementing, mysql


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Freshly installed Mysql (mysql-community-server) fails to start cpartsenidis Linux - Software 2 02-12-2015 12:41 AM
MySQL (mysqld) fails to start! dot_pro Linux - Server 1 09-27-2011 02:56 PM
Problem changing mysql uid,gid: mysql start fails gjatute Linux - Newbie 7 02-25-2010 01:38 AM
AUTO_INCREMENT + alphanumeric in MySQL? ta0kira Programming 12 10-03-2008 12:46 PM
Mysql auto_increment problem. wood Programming 1 02-25-2004 10:40 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:02 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration