当前位置: 首页 > news >正文

mysql数据库的基本管理

目录

一.数据库的介绍

 二.mariadb的安装

三.软件基本信息

 四.数据库开启

五.数据库的安全初始化

六.数据库的基本管理

七.数据密码管理

八.用户授权

 九.数据库的备份

十.web控制器


一.数据库的介绍

1.什么是数据库
数据库就是个高级的表格软件
2.常见数据库
Mysql Oracle mongodb db2 sqlite sqlserver …
3.Mysql (SUN -----> Oracle)
4.mariadb
数据库中的常用名词
1.字段 :表格中的表头
2.表 :表格
3.库 :存放表格的目录
4.查询 :对表格中的指定内容进行查看

 二.mariadb的安装

dnf install mariadb-server.x86_64 -y

三.软件基本信息

mariadb.service ##启动服务
3306 ##默认端口号
/etc/my.cnf.d/mariadb-server.cnf ##主配置文件
/var/lib/mysql ##数据目录,当需要重新安装mariadb时需要清理此目录或备份

 四.数据库开启

五.数据库的安全初始化

1.关闭数据库开放端口

vim /etc/my.cnf.d/mariadb-server.cnf
[mysqld]
skip-networking=1
systemctl restart mariadb
netstatus -antlupe | grep mysql #此命令查询不到端口

mariadb默认开放3306端口,是为了加强数据库的安全性,避免其他人员通过端口访问数据,我们可以修改配置文件,设置跳过网络功能开启数据库 

 

2.执行安全初始化脚本 

mysql_secure_installation
[root@Mariadb ~]# mysql ##默认不需要密码,初始化完毕后需要
ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: NO)
[root@Mariadb ~]# mysql -uroot -p ## -u 指定登陆用户 -p 密码

 以下是mysql的安全初始化过程,会设置到密码,是否允许匿名用户登录,是否允许超级用户远程登录,等等,我们将这些初始化设置之后就可以登录使用

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDBSERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.Enter current password for root (enter for none): 
OK, successfully used password, moving on...Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.You already have your root account protected, so you can safely answer 'n'.Switch to unix_socket authentication [Y/n] y
Enabled successfully!
Reloading privilege tables..... Success!You already have your root account protected, so you can safely answer 'n'.Change the root password? [Y/n] 
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..... Success!By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.Remove anonymous users? [Y/n] ... Success!Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.Disallow root login remotely? [Y/n] ... Success!By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.Remove test database and access to it? [Y/n] - Dropping test database...... Success!- Removing privileges on test database...... Success!Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.Reload privilege tables now? [Y/n] ... Success!Cleaning up...All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.Thanks for using MariaDB!

六.数据库的基本管理

1.查看
SHOW DATABASES; ##显示库名称
USE mysql; ##进入mysql库
SHOW TABLES; ##显示库中的所有表
SELECT * FROM user; ##查询所有数据
SELECT Host,User,Password FROM user; ##查询指定字段
SELECT Host FROM mysql.user WHERE User=‘root’
2.新建
CREATE DATABASE westos; ##新建库
CREATE TABLE linux ( ##新建表
username varchar(6) not null,
password varchar(30) not null
);
DESC linux; ##显示表结构
INSERT INTO linux VALUES (‘user1’,‘123’); #插入数据
FLUSH PRIVILEGES; #刷新数据库
3.更改
ALTER TABLE redhat RENAME linux;
ALTER TABLE linux ADD age varchar(4) AFTER password;
ALTER TABLE linux DROP age;
UPDATE linux SET sex=‘g’ WHERE username=‘user2’;
4.删除
DELETE from linux where username=‘user2’ and age=‘18’;
DROP TABLE linux;
DROP DATABASE westos;
===

 

 

以下是在数据库中新建更改以及删除数据

创建一个库

插入数据

更改表名

查看表的结构

表增加新的字段

删除字段

指定添加字段的位置

更新数据

删除表中内容

删除字段

删除表

删除库

七.数据密码管理

1.数据密码更改
mysqladmin -uroot -p123456 password westos

 2.数据库密码破解

systemctl stop mariadb
mysqld_safe --skip-grant-tables &
UPDATE mysql.user set Password=password(‘123456’) WHERE User=‘root’; ##当未使用过mysladmin更改过密码
UPDATE mysql.user set authentication_string=password(‘123456’) WHERE User=‘root’; ##当使用过
mysladmin更改过密码
flush privileges;
ps aux | grep mysql
kill -9 mysql的所有进程
systemctl start mariadb

 

八.用户授权

CREATE USER lee@localhost identified by ‘lee’; ##只能用localhost登陆
CREATE USER lee@% identified by ‘%’; ##可以通过网络或localhost登陆
GRANT INSERT,SELECT ON westos.* TO lee@localhost;
SHOW GRANTS for lee@localhost;
REVOKE SELECT ON westos.* FROM lee@localhost;
DROP user lee@localhost;

 建立用户

创建表

登录lee用户查看,什么都看不到(没有权限)

 查看权力(无权利)

授权

收回授权

 

 九.数据库的备份

mysqldump -uroot -p123 --all-database
mysqldump -uroot -p123 --all-database --no-data
mysqldump -uroot -p123 westos
mysqldump -uroot -p123 westos > /mnt/westos.sql
test1:
mysql -uroot -p123 -e “create database westos;”
mysql -uroot -p123 westos < /mnt/westos.sql
test2:
vim /mnt/westos.sql
CREATE DATABASE westos;
USE westos;
mysql -uroot -p123 < /mnt/westos.sql

备份 

回复

 先是删掉westos库

1

2

 

直接编辑/mnt/westos.sql

 

十.web控制器

dnf install httpd php php - mysqlnd - y
systemctl enable -- now httpd systemctl stop firewalld
cp phpMyAdmin - 3.4.0 - all - languages.tar.gz / var / www / html /
cd / var / www / html /
tar zxf phpMyAdmin - 3.4.0 - all - languages.tar.gz
mv phpMyAdmin - 3.4.0 - all - languages / mysqladmin
cd mysqladmin
cp config.sample.inc.php config.inc.php
firefox http :// 192.168.10.130 / mysqladmin

 

下载phpmyadmin解压

复制文件

相关文章:

  • ansible实用模块
  • LLM基础概念:Prompt
  • Desmos图形计算器分段函数
  • SpringBoot日志详解
  • 传输大咖47 | 软件企业文件传输难题?这款FTP替代工具了解一下
  • python/爬虫技术/lxml工具介绍/XML和HTML解析
  • LVS-DR实战案例,实现四层负载均衡
  • TomCat乱码问题
  • EasyAR自定义相机RTSP视频流(CustomCamera)
  • 【UR #1】外星人(dp思维技巧)
  • Java项目: 基于SpringBoot+mybatis+maven+vue图书进销存管理系统分前后台(含源码+数据库+毕业论文)
  • Linux开机logo设置
  • Unity中分辨率适配
  • AMEYA360:村田电子更适合薄型设计应用场景的3.3V输入、12A输出的DCDC转换IC
  • 如何在 UniApp 中实现地图的视野自适应?
  • CentOS7 安装JDK
  • Facebook AccountKit 接入的坑点
  • k个最大的数及变种小结
  • linux安装openssl、swoole等扩展的具体步骤
  • Making An Indicator With Pure CSS
  • miniui datagrid 的客户端分页解决方案 - CS结合
  • MySQL主从复制读写分离及奇怪的问题
  • node-glob通配符
  • React-生命周期杂记
  • Redis 懒删除(lazy free)简史
  • VuePress 静态网站生成
  • yii2权限控制rbac之rule详细讲解
  • 基于Mobx的多页面小程序的全局共享状态管理实践
  • 讲清楚之javascript作用域
  • 聊聊flink的BlobWriter
  • 判断客户端类型,Android,iOS,PC
  • 前端设计模式
  • 使用权重正则化较少模型过拟合
  • 新版博客前端前瞻
  • 一加3T解锁OEM、刷入TWRP、第三方ROM以及ROOT
  • 3月7日云栖精选夜读 | RSA 2019安全大会:企业资产管理成行业新风向标,云上安全占绝对优势 ...
  • PostgreSQL之连接数修改
  • 容器镜像
  • ‌‌雅诗兰黛、‌‌兰蔻等美妆大品牌的营销策略是什么?
  • (C++)八皇后问题
  • (html5)在移动端input输入搜索项后 输入法下面为什么不想百度那样出现前往? 而我的出现的是换行...
  • (ISPRS,2021)具有遥感知识图谱的鲁棒深度对齐网络用于零样本和广义零样本遥感图像场景分类
  • (附源码)计算机毕业设计SSM基于java的云顶博客系统
  • (官网安装) 基于CentOS 7安装MangoDB和MangoDB Shell
  • (考研湖科大教书匠计算机网络)第一章概述-第五节1:计算机网络体系结构之分层思想和举例
  • (四)activit5.23.0修复跟踪高亮显示BUG
  • (算法)Game
  • (一)Thymeleaf用法——Thymeleaf简介
  • (转)可以带来幸福的一本书
  • (轉)JSON.stringify 语法实例讲解
  • ***原理与防范
  • .Net 8.0 新的变化
  • .NET Framework、.NET Core 、 .NET 5、.NET 6和.NET 7 和.NET8 简介及区别
  • .NET 反射的使用
  • .NET/C# 编译期能确定的字符串会在字符串暂存池中不会被 GC 垃圾回收掉