千家信息网

mysql初步入门概览

发表于:2024-09-22 作者:千家信息网编辑
千家信息网最后更新 2024年09月22日,下文主要给大家带来mysql初步入门概览,希望mysql初步入门概览能够带给大家实际用处,这也是我编辑这篇文章的主要目的。好了,废话不多说,大家直接看下文吧。API:Application Progr
千家信息网最后更新 2024年09月22日mysql初步入门概览

下文主要给大家带来mysql初步入门概览,希望mysql初步入门概览能够带给大家实际用处,这也是我编辑这篇文章的主要目的。好了,废话不多说,大家直接看下文吧。

API:Application Programming Interface,应用程序编程接口

ODBC:Open DateBase ConnectionDBMS:DateBase Manage System,数据库管理系统数据组织结构(逻辑结构)1)层次结构2)网状结构3)关系结构RDBMS:Relational DateBase Manage System,关系型数据库管理系统
用户视图DBA视图物理视图RDBMS应该具备的功能1、数据库创建、删除、修改2、表创建、删除、修改3、索引的创建、删除4、用户和权限5、数据增、删、改6、查

相关命令

DML:Data Manipulate Language,数据操作语言 INSERT,REPLACE,UPFATE,DELETE
DDL:Data Definition Language,数据定义语言 CREATE,ALTER,DROP
DCL:Data Control Language,数据控制语言 GRANT,REVOKE
SELECTSQL:Structured Quiry LanguageRDBMS: Oracle,Sybase,Infomix(被IBM收购)、SQL Server(是Sybase的变种),DB2(IBM) MySQL,egrepSQL→PostgreSQL(pgsql)→ EnterpriseDB
Ali去IOE化,IBM,Oracle,EMC综合软件提供服务商IBM:CPU,AIX(Advanced IBM Unix),云服务器,DB2SUN:CPU,Solaris,云服务器,MySQL,Java → 被Oracle收购BEA:提供WebLogicPeopleSoft:提供客户端管理软件OpenOffice(SUN):被Oracle收购,私有化失败LibreOffice(OpenOffice作者)另起炉灶MariaDB,MySQL的作者继续开发MySQL → (二次开发)Percona非关系模型:NoSQL(一种技术) MongoDB:文档数据库
Redis:缓存数据库
HBase:基于键值的数据库,稀疏数据库
DBMS应具备的功能数据管理的独立性;有效存取数据;校验数据完整性和安全性;数据集中管理;并发存储和故障恢复;减少应用程序开发的时间。SQL命令 → 分析器(分析SQL语法) → 计划执行器(有多少种方式可以完成任务) → 优化器 → 文件存取方法 MySQL Community Edition
Enterprise Edtion,增加了备份功能
官方网站www.mysql.comMySQL软件包的格式 软件包管理器特有的格式 rpm,exe 通用二进制格式
源程序
客户端:mysql服务端:mysqld监听tcp/3306RDBMS数据位置/var/lib/mysql安装
  1. yum install mysql-server
初始化service mysqld start首次启动,完成对数据库内部元数据的初始化。PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !To do so, start the server, then issue the following commands:/usr/bin/mysqladmin -u root password 'new-password'/usr/bin/mysqladmin -u root -h hiyang.com password 'new-password'Alternatively you can run:/usr/bin/mysql_secure_installationwhich will also give you the option of removing the testdatabases and anonymous user created by default. This isstrongly recommended for production servers.See the manual for more instructions.You can start the MySQL daemon with:cd /usr ; /usr/bin/mysqld_safe &You can test the MySQL daemon with mysql-test-run.plcd mysql-test ; perl mysql-test-run.plPlease report any problems with the /usr/bin/mysqlbug script!mysql -u USERNAME,默认root -p,默认为空 -h MYSER_SERVER,默认localhost -h 127.0.0.1 Linux: socket Windows: memorymysql客户端: 交互式模式 批处理模式 执行mysql脚本交互式模式中的命令类别: 客户端命令云服务器端命令 必须使用语句结束符,默认为分号;SQL接口: Oracle, PL/SQL SQL Server, T-SQL关系型数据库对象 表
索引
视图(虚表)
约束
存储过程
存储函数
触发器
游标
用户 权限
事务
表: 行(row),列(field,column)
表:实体
字段名称,数据类型(强类型),类型修饰符(限制)



占空间范围备注

字符型
不区分大小写
CHAR(n)
n字节
255

VARCHAR(n)
n+1多结束修饰符
65535
变长
区分大小写
BINARY(n)
n字节


VARBINARY(n)
n+1字节

变长
不区分大小写TEXT(n)
n+2字节65535
区分大小写BLOB(n)

65535
binary large object




数值







整型


TINYINT
1字节
256

SMALLINT
2字节
65535

MEDIUMINT
3字节


INT
4字节

NOT NULL
BIGINT
8字节

UNSIGNED,无符号
DECIMAL


十进制
近似数值

FLOAT
4字节


DOUBLE
8字节


日期时间

DATE



TIME



DATETIME



TIMESTAMP



布尔





内置

枚举
ENUM


ENUM('M','F')
集合
SET


SET('M','F')
创建数据库
create database [ if not exists ] db_name;
删除数据库
drop database [ if not exists ] db_name;
查看库中的表
show tables from db_name;

创建表
create table tb_name(col1,col2,...)
  1. mysql> create table student(name char(10) not null,age tinyint unsigned,gender char(1) not null);
查看表的结构
desc tb_name;
删除表
drop table tb_name;修改表alter table tb_name modif 修正field的属性mysql> alter table student modify course varchar(50);change 改变field的名称mysql> alter table student change course lesson varchar(50); add 增加fieldmysql> alter table student add high int after age;mysql> alter table student add course varchar(100); drop 删除fieldmysql> alter table student drop lesson;
对数据的操作
插入数据
insert into tb_name (col1,col2,...) values|value ('STRING', NUM,...);insert into tb_name (col1,col2,...) values|value ('STRING', NUM,...), ('STRING', NUM,...),...;
在指定字段插入数据
mysql> insert into student (name,gender) value ('Li','M'),('Yang','F');mysql> select * from student;+------+------+------+--------+--------+| name | age | high | gender | lesson |+------+------+------+--------+--------+| Li | NULL | NULL | M | NULL || Yang | NULL | NULL | F | NULL |+------+------+------+--------+--------+
不指定字段,使用默认字段
mysql> insert into student value ('Zhang',26,162,'M','food');Query OK, 1 row affected (0.00 sec)mysql> select * from student;+-------+------+------+--------+--------+| name | age | high | gender | lesson |+-------+------+------+--------+--------+| Li | NULL | NULL | M | NULL || Yang | NULL | NULL | F | NULL || Zhang | 26 | 162 | M | food |+-------+------+------+--------+--------+
修改数据
update tb_name set column=value WHERE mysql> update student set high=178 where name='yang';Query OK, 1 row affected (0.00 sec)Rows matched: 1 Changed: 1 Warnings: 0 mysql> select * from student;+-------+------+------+--------+--------+| name | age | high | gender | lesson |+-------+------+------+--------+--------+| Li | NULL | NULL | M | NULL || Yang | NULL | 178 | F | NULL || Zhang | 26 | 162 | M | food |+-------+------+------+--------+--------+
删除数据
delete from tb_name where CONDITION;mysql> delete from student where name='Li';
选择
SELECT 字段 FROM tb_name WHERE CONDITION *: 所有字段 不指定WHERE:表示显示所有行;mysql> select name,high from student where lesson='food';+-------+------+| name | high |+-------+------+| Zhang | 162 |
创建用户
create user 'username'@'host' [identified by 'password'];
删除用户

drop user 'username'@'host';

HOST:IP: HOSTNAME: NETWORK: 通配符 _:匹配任意单个字符, 172.16.0._ %:匹配任意字符;DCL:
授权用户
grant pri1,pri2,... on db_name.tb_name to 'username'@'host' [identified by 'password'];不存在的话直接创建并授权
取消授权
revoke pri1,pri2,... on db_name.tb_name from 'username'@'host';
查看用户的授权
show grants for 'username'@'host'; ALL PRIVILEGES添加用户密码后才能有登录权限mysql> create user 'jerry'@'%';mysql> show grants for 'jerry'@'$';ERROR 1141 (42000): There is no such grant defined for user 'jerry' on host '$' mysql> create user 'tom'@'%' identified by 'tom';Query OK, 0 rows affected (0.00 sec)mysql> show grants for 'tom'@'%';+---------------------------------------------------------------------------+| Grants for tom@% |+---------------------------------------------------------------------------+| GRANT USAGE ON *.* TO 'tom'@'%' IDENTIFIED BY PASSWORD '675bd1463e544441' |+---------------------------------------------------------------------------+为用户设定密码:1、mysql>set password for 'username'@'host'=password('password'); 2、# mysqladmin -uusername -hhost -p password 'password' 3、mysql> update user set password=password('password') where user='root' and host='127.0.0.1';蓝色的password为函数select User,Host,Password from user;+-------+--------------+------------------+| User | Host | Password |+-------+--------------+------------------+| root | localhost | 565491d704013245 || root | hiyang.com | 565491d704013245 || root | 127.0.0.1 | || | localhost | || | hiyang.com | || jerry | % | || tom | % | 675bd1463e544441 || root | 192.168.8.40 | 565491d704013245 |+-------+--------------+------------------+ mysql图形化客户端工具1、phpMyAdmin2、Workbench3、MySQL Front4、Navicat for MySQL5、Toad# yum install php53-php
测试php与mysql通信phpmyadmin将下载的文件解压到DocumentRoot下,在浏览器用路径访问即可

对于以上关于mysql初步入门概览,大家是不是觉得非常有帮助。如果需要了解更多内容,请继续关注我们的行业资讯,相信你会喜欢上这些内容的。

0