本文共 2224 字,大约阅读时间需要 7 分钟。
MySQL是一种开放源代码的关系型数据库管理系统(RDBMS),主要使用结构化查询语言(SQL)进行数据库管理。其开源性质使得用户能够根据需求对数据库进行个性化修改。MySQL以高效性、可靠性和适应性著称,是内容管理的理想选择。
create user knightzz01@127.0.0.1 identified by '123456';
create user knightzz01@'%' identified by '123456';
grant all on knightzz01.* to knightzz01;
grant all on knightzz01.* to knightzz01;
revoke all on test.* from zn;
show grants for knightzz01;
delete user knightzz01@127.0.0.1 identified by '123456';
show databases;
use test;
create database test default character set utf8;
创建表:
create table student( id int(11) primary key, name varchar(10), age int(10) not null, gender varchar(2));
查看表:
show tables;
删除表:
drop table student;
查看表结构:
desc student;
修改表(常用前缀:alter table
)
alter table student add (address varchar(20), hobby varchar(20));
alter table student modify hobby int;
alter table student change hobby newHobby varchar(15);
alter table student drop newHobby;
alter table student rename to stu;
insert into stu (id, name, age, gender) values (2, '李华', 19, '男');
update stu set age=23, name='张楠' where id=1;
=
、!=
、<
、>
、<=
、>=
、between...and
、in(())
、is null
、not
、or
、and
delete from stu where id=1;
datetime
、date
、time
。int
、int unsigned
。tinyint
(0-255)、smallint
(-32767~32767)、mediumint
、int
、bigint
。tinyint unsigned
(0-255)、decimal
(精确小数)。float(M,D)
:M为有效位数,D为小数位数。 float(5,3)
存储小数点后3位,最大值为99.999。char(n)
和varchar(n)
: char(n)
:固定长度n,存储n个字符。varchar(n)
:可变长度,存储实际字符数+1字节。varchar
支持文本存储,不会截断空格。text
:大容量文本类型,无固定长度限制。enum
:枚举类型,最多包含65535个成员。set
:集合类型,最多包含64个成员。primary key
和unique
约束。index
,提高查询效率。index
提高查询速度。join
和union
,避免全表扫描。group by
和having
筛选数据。update
和delete
语句,尽量减少全表扫描。通过以上操作,您可以熟练掌握MySQL的常用操作和数据库开发技巧。
转载地址:http://pgffk.baihongyu.com/