mysql基本語句

2022-07-16 08:39:08 字數 1734 閱讀 7403

mysql -u root -p;  

登入資料庫

show databases;  

展示資料庫

show tables;

展示表desc messages;  

檢視messages表的結構

drop database lovestory;  

刪除lovestory資料庫

create table messages (

id int primary key auto_increment,

name varchar(50),

article text,

created_at timestamp

)engine=innodb default charset=utf8;  

建立messages表

(innodb型別支援事務。mysql預設採用myisam引擎,該型別表不支援事務,僅儲存資料,優點在於讀寫很快。)

alter table photo rename photos;

修改表名

alter table messages modify article text;

修改字段資料型別

(article:欄位名,text:要修改成的型別)

alter table messages change article myarticle varchar(1000);

修改欄位名

alter table messages add update_at timestamp;

增加字段

alter table messages drop update_at;

刪除字段

drop table messages;

刪除表select * from messages;

查詢表中的所有資料

select name from messages where id=1;

查詢表中id為1的資料的名字

select count(*) from messages where name='zhangsan';

查詢表中name為zhangsan的資料條數

insert into messages values(1 , 'joyce', 'hehe', '2014-12-13 21:56:03');

insert into messages(name,text) values('joyce', 'heheda');

插入資料

update messages set name='qsq',article='hehe' where id=1;

更新資料

delete from messages where id=1;

刪除資料

mysqldump -u root -p lovestory > lovestory.sql

匯出lovestory資料庫到lovestory.sql檔案

mysqldump -u root -p lovestory messages > messages.sql

匯出messages資料表到messages.sql檔案

source e:/lovestory/lovestory.sql

匯入資料庫,資料表

mysqladmin -u root -p password 123456

set password for root@localhost = password('123456');

把root的密碼改成123456

mysql基本語句 mysql基本語句

mysql關係型資料庫rds中的老大哥,增刪改查是mysql入門的基礎 增刪改查語句 增刪改查的語句命令為 增 insert 刪 delete 改 update 查 select或者show 庫操作建立資料庫 create database shujukuba 建立帶字符集的資料庫 create d...

mysql了基本語句 MySQL基本語句大全

mysql指令碼的基本組成 與常規的指令碼語言類似,mysql 也具有一套對字元 單詞以及特殊符號的使用規定,mysql 通過執行 sql 指令碼來完成對資料庫的操作,該指令碼由一條或多條mysql語句 sql語句 擴充套件語句 組成,儲存時指令碼檔案字尾名一般為 sql。在控制台下,mysql 客...

MySQL基本語句

mysqld 啟動資料庫 mysql uroot 登陸使用者名稱或密碼 show databases 顯示所有資料庫 use 使用 資料庫 show tables 顯示該資料庫下的所有 select from table 查詢該錶 insert into table values 插入資料到表 de...