MySql(一)

2022/8/24 2:22:51

本文主要是介绍MySql(一),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

安装MySql

首先下载MySql,下载地址为https://dev.mysql.com/downloads/windows/installer/5.7.html

MySQL安装成功后,需要配置到环境变量,配置成功后,就可以登录到MySQL了,客户端登录的命令具体为:

mysql -h localhost -u root -p

数据库的管理

database:数据库

table:表 表里面存储数据都是行列的模式

数据类型:

1、varchar(20)

2、int

3、double

创建数据库

create database databaseName;

查看数据库

show databases;

删除数据库

drop database databaseName;

进入数据库

use databaseName;

查询当前数据库

select database();

查询数据库版本

select version();

查看数据库的基本信息配置

status;

查询当前时间

select now();

别名

select now() as 当前时间

查看连接

show variables like  '%connection%';

查看超时

show variables like  '%timeout%';

表的结构管理

查看数据库中有哪些表

show tables;

创建表

create table tableName(Field Type(size));

查看表的结构

desc tableName;

查看表的创建过程

show create table tableName \G;

show create table tableName \g;

创建表的时候指定存储引擎与编码

create table user(name varchar(20),age int,address varchar(80))ENGINE=InnoDB DEFAULT CHARSET=utf8;

 

 

修改表的名称

rename table oldTableName to newTableName;

字段管理

添加字段

添加的字段在首位

alter table tableName add addFiled type first;
desc tableName;

XX字段添加在XX字段的后面

alter table user add addFiled type after existFiled;
desc tableName;

添加字段,默认是在最后一列

alter table user add addFiled type;
desc tableName;

修改字段名

alter table tableName change oldFiled newFiled type;
desc tableName;

修改字段类型

alter table tableName modify Field newType;

删除字段名

alter table tableName drop Field;

增加字段备注

create table user(Field type comment "注释");

修改字段的注释

alter table tableName modify Field type comment "注释";

MySQL的DML语句

INSERT

插入一个字段的一个值

insert into std_info(name) values("zhangsan");
select * from std_info;

插入一行数据

insert into std_info values("zhangsan",10);
select * from std_info;

插入多行数据

insert into std_info values("zhangsan",10),("lisi",20),("wangwu",30);
select * from std_info;



这篇关于MySql(一)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程