Windows:
mysqld --initialize --console #初始化数据库
mysqld install .sql #安装sql服务
#打开服务 net start .sql
#删除服务 sc delete .sql
mysql -uroot -pXXXXX #XXXXX是初始化的密码
alter user root@localhost identified by '123456'; #修改密码
show databases;#显示所有的数据库
show tables; #显示所有的表
create database xxx; #创建数据库名字为xxx
drop table xxx; #删除表
drop database xxx; #删除数据库
use xxx;#进入xxx数据库,为了操作里面的表
#建立客户资料表,如果创建过,则忽略
create table if not exists kehuziliao
(
kehuziliaoid char(50) not null,
name char(50) not null,
age char(50) not null,
addr char(100) not null,
primary key(kehuziliaoid)
)charset=utf8;
#建立订单表,如果创建过,则忽略
create table if not exists splist
(
splistid char(50) not null,
kehuid char(50) not null,
time char(50) not null,
spname char(50) not null,
num char(50) not null,
snum char(50) not null,
xsname char(50) not null,
primary key(splistid)
)charset=utf8;
#插入kehuziliao数据
insert into kehuziliao
(kehuziliaoid, name, age, addr)
values
('1','zhangsan','25','hebei/ts');
#插入splist数据
insert into splist
(splistid,kehuid,time,spname,num,snum,xsname)
values
('1','1',REPLACE(unix_timestamp(current_timestamp(3)),'.',''),'华为手机Mate200 64GB+2TB','1','10999','zhangsan')
#修改splist的商品价格为12999
update splist set snum='12999' where splistid='1';
#创建一个视图 关联两个表的数据。
create view list0 as select * from kehuziliao A,splist B where A.kehuziliaoid=B.kehuid;
#查询表
select * from list0;
mysql 初始化笔记
于 2024-03-05 22:26:10 首次发布