一、mysql服务
1、常见数据库的类型
1)关系数据库
按照统一的标准和数据类型进行存储数据
常见的数据库产品
mysql、sql server、oracle、sdb2
2)非关系型数据库
用于缓存数据使用
存储数据内容多样化
redis、mongodb
2、mysql的作用和特点
1)mysql作用
存储海量结构化数据
减小数据冗余
保证数据的真实性有效性一致
2)mysql的特点
支持多线程数据库
支持多用户访问
采用c/s设计结构
使用简单易用
开源成本低
小型企业使用
3、安装mysql
1)安装依赖程序
[[email protected] ~]# yum -y install ncurses-devel cmake
2)创建管理mysql账户
[[email protected] ~]# groupadd mysql
[[email protected] ~]# useradd -M -s /sbin/nologin -g mysql mysql
3)配置mysql数据库
[[email protected] mysql-5.5.22]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DSYSCONFDIR=/etc
4)编译安装mysql
[[email protected] ~]# make && make install
4、初始化配置mysql
1)生成mysql主配置文件
[[email protected] mysql-5.5.22]# cp support-files/my-medium.cnf /etc/my.cnf
2)生成服务控制文件
[[email protected] mysql-5.5.22]# cp support-files/mysql.server /etc/init.d/mysqld
[[email protected] mysql-5.5.22]# chmod +x /etc/init.d/mysqld
3)添加为系统服务设置开机自动启动
[[email protected] ~]# chkconfig --add mysqld
[[email protected] ~]# chkconfig --level 35 mysqld on
4)优化mysql命令
[[email protected] ~]# vim /etc/profile
/etc/profile
PATH=$PATH:/usr/local/mysql/bin/
[[email protected] ~]# source /etc/profile
5)设置mysql目录的所有者
[[email protected] ~]# chown -R mysql:mysql /usr/local/mysql/
6)初始化mysql服务
[[email protected] ~]# /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
7)启动mysql服务设置开机自启
[[email protected] ~]# systemctl start mysqld
[[email protected] ~]# systemctl enable mysqld
8)监听mysql端口号
[[email protected] ~]# netstat -anptu | grep 3306
9)设置mysql初始化密码
[[email protected] ~]# mysqladmin -uroot password
10)登录mysql服务器
[[email protected] ~]# mysql -uroot [email protected]
Mysql数据库系统
2)查看数据库
mysql> show databases;
Mysql数据库系统
3)切换数据库mysql中
mysql> use mysql;
Mysql数据库系统
4)创建数据库benet
mysql> create database benet;
Mysql数据库系统
5)删除创建的benet数据库
mysql> drop database benet;
Mysql数据库系统
2、表的管理
1)创建student表
mysql> create table benet.student (mysql> create table benet.student (姓名 char(10),性别 char(3),成绩 int,身份证号码 char(16),primary key (身份证号码));
Mysql数据库系统
Mysql数据库系统

2)查看表的结构
mysql> desc benet.student;
Mysql数据库系统
3)查看创建的表
mysql> show tables;
Mysql数据库系统
4)删除表
mysql> drop table benet.student;
Mysql数据库系统
3、表中记录的管理
1)表中插入数据
mysql> insert into benet.student values (‘bob’,‘男’,100,‘111111111111111’);
Mysql数据库系统
2)查看表中数据
mysql> select * from benet.student;
Mysql数据库系统
3)查看姓名和成绩列
mysql> select 姓名,成绩 from benet.student
Mysql数据库系统
4)匹配身份证号码将性别修改为女
mysql> update benet.student set 性别=‘女’ where 身份证号码=‘222223331111111’;
Mysql数据库系统
Mysql数据库系统
5)删除表中的记录
mysql> delete from benet.student where 姓名=‘bob’;
Mysql数据库系统
6)删除表中所有记录
mysql> delete from benet.student;
Mysql数据库系统
4、维护数据库和数据库权限的管理
1)维护数据库的权限类型
all:完全控制权限
select:允许查询
insert:允许插入新数据
update:允许更新数据
delete:删除数据
2)授权bob账户拥有完全控制权限对benet数据库所有表
mysql> grant all on benet.* to ‘bob’@‘localhost’ identified by '[email protected]
Mysql数据库系统
3)查看授权权限
mysql> show grants for ‘bob’@‘localhost’;
Mysql数据库系统
4)使用bob登录数据库
[[email protected] ~]# mysql -ubob [email protected]
Mysql数据库系统
5)撤销授权,撤销所有权限
mysql> revoke all on benet.* from ‘tom’@‘localhost’;
Mysql数据库系统

相关文章: