mysql之查找所有數(shù)據(jù)庫(kù)中沒(méi)有主鍵的表問(wèn)題
查找所有數(shù)據(jù)庫(kù)中沒(méi)有主鍵的表
select table_schema,table_name from information_schema.tables where (table_schema,table_name) not in( select distinct table_schema,table_name from information_schema.columns where COLUMN_KEY='PRI' ) and table_schema not in ( 'sys','mysql','information_schema','performance_schema' --排除系統(tǒng)庫(kù) );
修改mysql數(shù)據(jù)表主鍵
這里以網(wǎng)上copy的建表語(yǔ)句為例
create table users ( ? ? name ? ? ?varchar(50) ? ? ? ? ? ? ? ? ? ? ? ? null, ? ? salt ? ? ?char(4) ? ? ? ? ? ? ? ? ? ? ? ? ? ? null comment '鹽', ? ? password ?varchar(255) ? ? ? ? ? ? ? ? ? ? ? ?null comment '密碼', ? ? create_at timestamp default CURRENT_TIMESTAMP null comment '創(chuàng)建時(shí)間', ? ? update_at timestamp default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '修改時(shí)間', ? ? tid ? ? ? int unsigned auto_increment ? ? ? ? primary key ) ? ? charset = utf8;
mysql的版本是8,這里要把主鍵tid改為id。需改自增主鍵需要三步驟
先刪除掉自增
alter table ?users modify tid int not null;
再刪除主鍵
alter table ?users drop primary key;
修改名稱
alter table ?users change tid id int unsigned auto_increment primary key;
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Linux系統(tǒng)利用crontab定時(shí)備份Mysql數(shù)據(jù)庫(kù)方法
本文教你如果快速利用系統(tǒng)crontab來(lái)定時(shí)執(zhí)行備份文件,按日期對(duì)備份結(jié)果進(jìn)行保存2021-09-09MySQL性能優(yōu)化之Open_Table配置參數(shù)的合理配置建議
這篇文章主要介紹了MySQL性能優(yōu)化之Open_Table配置參數(shù)的合理配置建議,在MySQL數(shù)據(jù)庫(kù)中,Opened_tables表示打開(kāi)過(guò)的表數(shù)量,需要的朋友可以參考下2014-07-07SQL中的開(kāi)窗函數(shù)(窗口函數(shù))
這篇文章主要介紹了SQL中的開(kāi)窗函數(shù)(窗口函數(shù))使用,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-08-08

mysql 8.0 錯(cuò)誤The server requested authentication method unkno

Linux如何添加mysql系統(tǒng)環(huán)境變量