MYSQL基本操作

2021-10-19 10:50:14 字數 1570 閱讀 7844

選擇

select 列名稱 from 表名稱

select lastname,firstname from persons

select distinct 列名稱 from 表名稱

select distinct company from orders

where 子句

select 列名稱 from 表名稱 where 列 運算子 值

select * from persons where firstname='bush'

and 和 or 運算子

select * from persons where firstname='thomas' and lastname='carter'

select * from persons where firstname='thomas' or lastname='carter'

select * from persons where (firstname='thomas' or firstname='william')

and lastname='carter'

order by 語句排序

select company, ordernumber from orders order by company desc

select company, ordernumber from orders order by company desc, ordernumber asc

insert into 插入新的行

insert into 表名稱 values (值1, 值2,....)

insert into table_name (列1, 列2,...) values (值1, 值2,....)

insert into persons values ('gates', 'bill', 'xuanwumen 10', 'beijing')

insert into persons (lastname, address) values ('wilson', 'champs-elysees')

update 修改表中資料

update 表名稱 set 列名稱 = 新值 where 列名稱 = 某值

update person set firstname = 'fred' where lastname = 'wilson'

update person set address = 'zhongshan 23', city = 'nanjing'

where lastname = 'wilson'

delete 刪除表中的行

delete from 表名稱 where 列名稱 = 值

delete from person where lastname = 'wilson'

delete * from table_name

mysql基本操作 MySQL基本操作

mysql中新增使用者,新建資料庫,使用者授權,刪除使用者,修改密碼 注意每行後邊都跟個 表示乙個命令語句結束 1.新建使用者 1.1 登入mysql mysql u root p 密碼 1.2 建立使用者 mysql insert into mysql.user host,user,passwor...

mysql 基本操作 mysql基本操作

mysql 建立表,並設定主鍵自增 create table log logid int 4 primary key not null auto increment,logtitle varchar 32 not null logcontent varchar 160 not null logtim...

mysql基本操作

1,檢視資料庫狀態 及啟動停止 etc init.d mysqld status etc init.d mysqld start etc init.d mysqld stop 2,給使用者配置初始密碼123456 mysqladmin u root password 123456 3,修改root使...