mysql的一些操作方法小結

2021-09-29 08:14:52 字數 1391 閱讀 2642

輸入:

mysql -uroot -p

緊接著會出現:password:

輸入設定的密碼即可。

注意:p後無「;」,如加上會出現錯誤。

輸入:exit

show databases;

操作成功:query ok

操作失敗:error

use 資料庫名;

操作成功:database changed

show tables

create table 表名(

欄位1,型別,約束(比如是否為空,是否有自增屬性,是否設定為主鍵),

欄位2,型別,約束(比如是否為空,是否有自增屬性,是否設定為主鍵),…)

注意:最後一行不用加逗號

eg :

create table student(

id bigint(20) not null auto_increment primary key,

name varchar(255),

age int(11)

)注:1.id是唯一的,primary key主鍵,使id唯一。

2. not null 意為不為空,即必須有值。

3.auto_increment 自增長。

4. 常用資料型別有:數值型(int,bigint,float),日期和時間型(date,time,datetime),字元型(varchar,char,text)。

5.英文佔乙個位元組,中文佔兩個位元組。

desc 表名

insert into 表名

(欄位名1,欄位名2…)(…第二行…)(…第三行…)

values

(值1,值2…)(…)(…)

注:若插入的值是字元(如字母或漢字),則應加雙引號。

(1).查

(2). 刪

(3).改

eg:

update student(表名) set name=「使用者3」(字段=值) where age = 11;

alter table 舊表名 rename to 新錶名;

aiter table 表名 add 新欄位名 列型別 位置(first或after …)

(修改名稱+資料型別):alter table 表名 change 舊列名 新列名 新資料型別;

(修改資料型別):alter table 表名 modify 列名 新資料型別;

alter table 表名 drop 列名;

相關的一些操作方法

create table tb user id int,name varchar 30 gender char 3 birthday datetime,salary double 7,2 插入資料 insert into 表名 列名,列名.列名 values 值1,值2.值n insert into...

MySql Docker的一些操作方法

偶爾有需求,涉及到資料庫的改動,那一定要表結構改動 程式除錯都先在測試環境淬鍊千百遍。現在流行微服務 docker部署,很容易拉起一整套環境。mysql image mysql 5.7.25 restart unless stopped command default authentication ...

Ruby中一些常用的檔案操作方法小結

檔案或目錄是否存在 複製 如下 file.exist?file path 是否為檔案 複製 如下 file.file?file path 是否為目錄 複製 如下 file.directory?file path 從路徑中獲取檔名 複製 如下 file.basename tmp adb.log adb...