mysql(mariadb)常用命令(持续更新ing)
生活随笔
收集整理的這篇文章主要介紹了
mysql(mariadb)常用命令(持续更新ing)
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
?
目錄
數(shù)據(jù)庫(kù)
創(chuàng)建數(shù)據(jù)庫(kù)
切換到某個(gè) 數(shù)據(jù)庫(kù)下
表
創(chuàng)建表
創(chuàng)建數(shù)據(jù)
更新表中數(shù)據(jù)
查看表結(jié)構(gòu)
重命名表
刪除重復(fù)數(shù)據(jù)
查看前n行數(shù)據(jù)
列
增加列?
修改列?
主鍵
刪除列
重命名列
mysql導(dǎo)入csv文件:
數(shù)據(jù)庫(kù)
創(chuàng)建數(shù)據(jù)庫(kù)
create database databaseName;切換到某個(gè) 數(shù)據(jù)庫(kù)下
use databaseName;表
創(chuàng)建表
create table tableName(dataName dataType); 例如: create table test(date int);創(chuàng)建數(shù)據(jù)
insert into person (number,name,birthday) values (1,'haha',20160509);更新表中數(shù)據(jù)
update person set name="xixi" where name="heihei";查看表結(jié)構(gòu)
desc tableName;重命名表
alter table t1 rename t2;刪除重復(fù)數(shù)據(jù)
mysql> CREATE TABLE tmp SELECT last_name, first_name, sex FROM person_tbl GROUP BY (last_name, first_name, sex); mysql> DROP TABLE person_tbl; mysql> ALTER TABLE tmp RENAME TO person_tbl;查看前n行數(shù)據(jù)
select * from tableName limit n;列
增加列?
alter table user add COLUMN new1 VARCHAR(20) DEFAULT NULL; //增加一列,默認(rèn)為空 alter table user add COLUMN new2 VARCHAR(20) NOT NULL; //增加一列 ,默認(rèn)不能為空 alter table TABLE_NAME add column NEW_COLUMN_NAME varchar(20) not null first;//在開頭添加列修改列?
alter table user MODIFY new1 VARCHAR(10); //修改一個(gè)字段的類型 alter table user CHANGE new1 new4 int; //修改一個(gè)字段的名稱主鍵
alter table tabelname add new_field_id int(5) unsigned default 0 not null auto_increment ,add primary key (new_field_id);//需要確保添加主鍵的列不能為空。添加主鍵Alter table tablename Drop Primary key;//刪除主鍵刪除列
alter table t2 drop column c;重命名列
alter table t1 change a b integer;mysql導(dǎo)入csv文件:
load data infile '/tmp/test.csv' into table test_info fields terminated by ',' optionally enclosed by '"' escaped by '"' lines terminated by '\r\n';參考鏈接:
https://blog.csdn.net/csdn10086110/article/details/89500065
https://www.cnblogs.com/Chenshuai7/p/5271445.html
https://www.cnblogs.com/lvdongjie/p/6274392.html
《新程序員》:云原生和全面數(shù)字化實(shí)踐50位技術(shù)專家共同創(chuàng)作,文字、視頻、音頻交互閱讀總結(jié)
以上是生活随笔為你收集整理的mysql(mariadb)常用命令(持续更新ing)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: FORTRAN学习记录(持续更新)
- 下一篇: Excel批量转csv格式