数据库-01
- 1.MySQL安装
-
- 2.MySQL初学
- 2.1 数据库基础-命令行形式
- 2.2 MySQL操作数据库和数据表
- 2.3 MySQL数据表基本数据类型
鸣谢:
参考文章:https://www.cnblogs.com/wupeiqi/articles/5713315.html
1.MySQL安装
1.1 官网下载
http://dev.mysql.com/downloads/mysql/
1.2 安装
初始化:
服务端
mysqld
root 无密码
2023-01-08T07:39:59.576240Z 0 [System] [MY-013169] [Server] D:\softwareWork\MySQL\mysql-8.0.31-winx64\bin\mysqld.exe (mysqld 8.0.31) initializing of server in progress as process 11524
2023-01-08T07:39:59.631242Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-01-08T07:40:12.726847Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2023-01-08T07:42:34.297497Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: %o)ywRVqo1>
启动服务端:
net start MySQL
net stop MySQL
登录:
mysql -u root -p
1.2.1 安装失败解决方案:
https://blog.csdn.net/qubernet/article/details/119677161
https://www.cnblogs.com/zcl789456/p/16586105.html
密码设置:
https://blog.csdn.net/wingrez/article/details/99825144
大小写敏感设置:
https://blog.51cto.com/jeecg/3196966
2.MySQL初学
2.1 数据库基础-命令行形式
连接:
show databases;
use {数据库名称};
show tables;
select * from 表名;
默认:用户root
创建用户:
create user 'alex'@'192.168.1.1' identified by '123123';
create user 'alex'@'192.168.1.%' identified by '123123';
create user 'alex'@'%' identified by '123123';
授权:
权限 人
grant select,insert,update on db1.t1 to 'alex'@'%'
2.2 MySQL操作数据库和数据表
3、学习SQL语句规则
操作文件夹(数据库)
create database db2;
create database db3 default charset utf8;
show databases;
drop database db2;
操作文件(数据表)
show tables;
create table t1(id int, name char(10));
create table t1(id int, name char(10)) default charset=utf8;
create table t1(id int, name char(10)) engine=innodb default charset=utf8;
create table t1(
列名 类型 null,
列名 类型 not null,
)
create table t1(
列名 类型 not null auto_increment,
列名 类型 not null default,
)
create table t3(id int auto_increment primary key, name char(10)) engine=innodb default charset=utf8;
create table t2(
id int not null auto_increment primary key,
name char(10)
)engine=innodb default charset=utf8;
innodb 支持事务
myisam 不支持事务,全局索引速度快
清空表:
delete from t2;
insert into t2(name) value ('alex');
truncate table t2;
删除表:
drop table t1;
select * from t1;
插入数据;
insert into t1(id,name) value (1,'alex');
insert into t1(id,name) value (1,'爱丽丝');
2.3 MySQL数据表基本数据类型
数据类型:
数字:
tinyint
int
bigint
FLOAT
DOUBLE
decimal 精准的小数(底层实现是字符串实现)
create table t1(
id int not null auto_increment primary key,
num decimal(10,5),
name char(10)
)engine=innodb default charset=utf8;
字符串:
char(10)
varchar(10)
text
mediumtext
longtext
上传文件:
文件存硬盘
db存路径
时间类型:
DATETIME
其他:
enum
示例:
CREATE TABLE shirts (
name VARCHAR(40),
size ENUM('x-small', 'small', 'medium', 'large', 'x-large')
);
INSERT INTO shirts (name, size) VALUES ('dress shirt','large'), ('t-shirt','medium'),('polo shirt','small');
set
示例:
CREATE TABLE myset (col SET('a', 'b', 'c', 'd'));
INSERT INTO myset (col) VALUES ('a,d'), ('d,a'), ('a,d,a'), ('a,d,d'), ('d,a,d');
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)