##1数据库管理系统类型## 1.DB2 IBM:关系型数据库管理系统,在不同操作系统服务; 2.Oracle 甲骨文:高效率、可靠性好的适应高吞吐量的数据库解决方案; 3.Mysql 甲骨文:业内广泛使用的web服务器解决方案,被称为LAMP; 4.SQL server 微软:使用方便可伸缩性好,相关软件集成程度高; 5.Sybase:典型的UNIX或WindowsNT环境下的大型关系型数据库系统; 6.Informix IBM:个集成解决方案,在线数据处理的旗舰数据服务系统; 7.Access 微软:结合JetData base Engine和图形化界面特点; 8.VFP 微软:在DOS上运行,与xBase系列相容; ##2.数据库的设置 ## 1.重置虚拟机,修改网络配置、主机名和yum源 2.安装数据库(mariadb)服务 若不知道mariadb的安装包: yum search mariadb 安装数据库: yum install mariadb-server.x86_64 -y 3.数据库相关设置 打开并设置开启自启动 systemctl start mariadb systemctl enable mariadb 查看数据库接口mysql ##3351接口打开不安全 netstat -antuple | grep mysql 关闭数据库接口(修改配置文件/etc/my.cnf) 修改数据库密码 mysql_secure_installation Enter current password for root (enter for none): Set root password? [Y/n] ##是否重置密码Y Remove anonymous users? [Y/n] ##是否移除匿名用户权限Y Disallow root login remotely? [Y/n] ##是否禁止root用户远程登陆Y Remove test database and access to it? [Y/n] ##是否移除test数据库Y Reload privilege tables now? [Y/n] ##是否更新表格Y 登陆数据库 ##注意:密码不要写在-p后(quit退出) ##3.数据库编辑 ## 1.显示数据库 show databases; ##切记分号!相当于ls 2.进入数据库 ##切记分号!相当于cd MariaDB [(none)]> use mysql; ##切换到mysql数据库中 3.显示数据库中的表格 show tables; ##切记分号!相当于ls 4.查询user表中的Host,User,Password信息 MariaDB [mysql]> select Host,User,Password from user; 5.查询user表的数据结构 desc user; ##切记分号! 6.新建数据库 create database westos; ##切记分号! 7.新建数据库westos中的表格 create table linux; MariaDB [westos]>create table linux ( -> username varchar(50) not null, ##字符类型为char,不能为空 -> password varchar(50) not null ); ##字符类型为char,不能为空 8.在linux表格中插入信息 insert into linux values('hello','123'); select * from linux; ##查看linux表格中的所有信息 9.修改linux表格中的信息(例:password) update linux set password='123321' where username='hello'; 10.在linux表格中添加age字段 alter table linux add age varchar(4) after username; 11.在linux表格中移除age字段 alter table linux drop age; 12.修改表格名字 alter table linux rename mydata; 13.删除表格中的某一行 delete from mydata where username='hello'; 14.删除表格 drop table mydata; 15.删除数据库 drop database westos; ##4.数据库用户管理## 1.用户创建 create user feng@localhost identified by 'westos'; ##feng@localhost 本地用户 ##hate@‘%’ 远程用户 2.用户授权 grant INSERT,SELECT on westos.* to feng@localhost; ##给本地hate用户对数据库westos的插入、显示权限 查看用户权限 show grants for feng@localhost; 3.此时用feng用户登陆实验 具备select权限,可以查看westos数据库: 4.撤销用户权限(切换root用户) revoke INSERT on westos.* from feng@localhost; 5.重载授权表 flush privileges; 6.删除用户 drop user feng@localhost ##5.数据库资料备份## 1.数据库资料备份方式 mysqldump -uroot -predhat --all-database > /mnt/data.all ##所有数据库资料备份 mysqldump -uroot -predhat --all-database --no-data > /mnt/data.err ##只备份数据结构,不备份数据 mysqldump -uroot -predhat westos > /mnt/westos.sql ##指定westos数据库的资料备份 2.数据恢复 mysql -uroot -predhat < /mnt/westos.sql 注意:当备份的数据库不存在时,会报错(例:删除westos数据库 恢复方式1:修改备份文件 /mnt/westos.sql 恢复后,登陆数据库查看 恢复方式2:建立westos数据库 mysql -uroot -predhat -e "create database westos;" mysql -uroot -predhat westos < /mnt/westos.sql ##6.用户密码更改## 1.若用户密码忘记,关闭数据库服务,跳过认证列表 systemctl stop mariadb.service mysqld_safe --skip-grant-tables & 2.进入数据库修改(mysql回车即可) update mysql.user set Password='123' where User='root'; 查看密码 select * from mysql.user ##以上修改密码为明文 以加密方式修改密码: update mysql.user set Password=password('123') where User='root'; 3.查看mysql相关进程(ps aux | grep mysql),全部关闭 kill -9 进程号 (所有的) 关闭后重启mysql服务,新密码登陆即可