mysql登錄:方法1:使用Command Line Client登錄,缺點:不顯示報錯信息 方法2:使用cmd登錄(cmd的常用:查看ip地址:ipcongfi 定時關機:shutdown -s -t 10800,3小時=180分鐘=180*60秒=10800秒)1.切換到mysql\bin目錄下 ...
mysql登錄:
方法1:
使用Command Line Client登錄,缺點:不顯示報錯信息
方法2:
使用cmd登錄(cmd的常用:查看ip地址:ipcongfi-----定時關機:shutdown -s -t 10800,3小時=180分鐘=180*60秒=10800秒)
1.切換到mysql\bin目錄下
2.mysql -u root -p
方法3:帶ip地址的登錄,可以是本機ip,也可以是遠程mysql伺服器的ip地址
mysql -h 192.168.1.5 -u root -p
方法4:
1.查看mysql當前埠號:show global variables like 'port';
2.停止服務,更改埠號,my.ini,啟動伺服器
3.mysql -u root -P 3307 -p
4.查看mysql當前埠號:show global variables like 'port';
方法5:
1.解決1130報錯
2.使用Navicat登錄
數據的命令:
創建庫:
create database 庫名稱;
create database test1;
create database if not exists test1;
修改庫:
自行學習
刪除庫:
drop database 庫名稱;
創建表:
create table 表名稱 (
欄位名1 欄位類型 欄位長度 [欄位約束],
欄位名2 欄位類型 欄位長度 [欄位約束],
欄位名3 欄位類型 欄位長度 [欄位約束]
);
create table linux (
cd datetime not null,
ls varchar(10) default "yes",
pwd int(4)
);
insert into linux values("2019-5-31","today","4444");
insert into linux values("2019-5-31","","4444");
insert into linux values("2019-5-31",default,"4444");
插入數據:
insert into 表名稱 values(v1,v2,v3);
insert into linux values("2019-5-31","today","4444");
insert into linux values("2019-5-31 16:36:50","today","4444");
insert into linux values("2019-5-32","today","4444");
insert into linux values("2019-5-31","today","1234567890");
insert into linux values("2019-5-31","today","12345678901");
insert into linux(cd,ls) values("2019-5-31","today");
insert into linux values("2019-5-31","today",default);
insert into linux values("2019-5-31","today","");
insert into linux values("2019-5-31","today",null);
修改表欄位類型:
ALTER TABLE 表名 MODIFY 欄位名 數據類型;
alter table linux modify pwd int;
alter table linux modify cd date;
修改表欄位排序:
ALTER TABLE 表名 MODIFY 欄位名1 數據類型 FIRST;
ALTER TABLE 表名 MODIFY 欄位名1 數據類型 AFTER 欄位名2;
ALTER TABLE linux MODIFY pwd int(11) AFTER cd;
ALTER TABLE linux MODIFY ls varchar(10) FIRST;
添加欄位:
ALTER TABLE 表名 ADD 新欄位名 數據類型;
ALTER TABLE 表名 ADD 新欄位名 數據類型 [FIRST|AFTER 已存在欄位名];
ALTER TABLE linux ADD mkdir float;
ALTER TABLE linux ADD rm double after cd;
刪除欄位:
alter tabel 表名 drop 原有欄位名;
alter tabel linux drop column rm;
資料庫欄位的約束表達
not null 非空約束
default 預設約束
primary key 主鍵約束
auto_increment 自增長
create table linux (
pwd int(4) primary key auto_increment,
cd datetime not null,
ls varchar(10) default "yes"
);
insert into linux values(1,"2019-6-3","123");
insert into linux values(default,"2019-6-3","123");
以下是練習
create table employee (
empid varchar(12) primary key comment "員工編號",
name varchar(12) not null comment "員工姓名",
sex int comment "性別",
title varchar(8) comment "職稱",
birthday date comment "生日",
depid varchar(10) comment "部門編號"
);
create table department (
depid varchar(12) primary key comment "部門編號",
depname varchar(8) comment "部門名稱",
info varchar(8) comment "部門簡介",
);
create table salary(
empid varchar(12),
basesalary int comment "基本工資",
stationsalary int comment "崗位工資"
);
insert into employee values(1001,"張三","1","高級工程師","1975-1-1",111);
insert into employee values(1002,"李四","0","助理工程師","1985-1-1",111);
insert into employee values(1003,"王五","1","工程師","1978-1-1",222);
insert into employee values(1004,"趙六","1","工程師","1979-1-1",222);
insert into department values(111,"生產部","1");
insert into department values(222,"銷售部","2");
insert into department values(333,"人事部","3");
insert into salary values(1001,2200,1100);
insert into salary values(1002,1200,200);
insert into salary values(1003,1900,700);
insert into salary values(1004,1950,700);
添加外鍵:
alter table salary add constraint FK_ID foreign key(empid) REFERENCES emoloyee (empid);
alter table employee add constraint FK_DEPID foreign key(empid) REFERENCES department(empid);
更改 表 員工表 添加 約束 約束名稱employee 外鍵(員工表的empid) 關聯 部門表(部門表的empid)