Linux下数据库管理之(mariadb)

一、数据库的介绍
1.1数据库就是个高级的表格软件,简单来说是数据库本身可视为电子化的文件柜–存储电子文件的处所,用户可以对文件中的数据进行新增、截取、更新、删除等操作。
1.2常见数据库
关系型数据库:SQLite、Oracle、Mysql
非关系型数据库:MongoDb、redis、HBase
1.3Mysql
MySQL 是一个关系型数据库管理系统,由瑞典 MySQL AB 公司开发,目前属于 Oracle 公司。MySQL 是一种关联数据库管理系统,关联数据库将数据保存在不同的表中,而不是将所有数据放在一个大仓库内,这样就增加了速度并提高了灵活性。

MySQL 是开源的,所以不需要支付额外的费用。
MySQL 支持大型的数据库。可以处理拥有上千万条记录的大型数据库。
MySQL 使用标准的 SQL 数据语言形式。
MySQL 可以运行于多个系统上,并且支持多种语言。这些编程语言包括 C、C++、Python、Java、Perl、PHP、Eiffel、Ruby 和 Tcl 等。
MySQL 对PHP有很好的支持,PHP 是目前最流行的 Web 开发语言。
MySQL 支持大型数据库,支持 5000 万条记录的数据仓库,32 位系统表文件最大可支持 4GB,64 位系统支持最大的表文件为8TB。
MySQL 是可以定制的,采用了 GPL 协议,你可以修改源码来开发自己的 MySQL 系统

1.4.mariadb
MariaDB 是一个采用 Maria 存储引擎的MySQL分支版本,是由原来 MySQL 的作者Michael Widenius创办的公司所开发的免费开源的数据库服务器。
二、mariadb基本信息
2.1安装软件

3306 ##默认端口号
/etc/my.cnf ##主配置文件 
/var/lib/mysql ##数据目录

在这里插入图片描述
在这里插入图片描述
三.数据库的安全初始化
3.1.关闭数据库开放端口
在这里插入图片描述
3.2.执行安全初始化脚本

[root@localhost ~]# mysql_secure_installation
[root@localhost ~]# mysql_secure_installation 

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS 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
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...   没有密码直接回车

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y    设置密码y
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] y    限制匿名用户登录y
 ... 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] y   限制超级用户远程登录y
 ... 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] y   删除测试户y
 - 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] y  刷新数据库y
 ... 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!

初始化完成后再次登录数据库需要输入密码
-u 指定用户
-p 需要输入密码

在这里插入图片描述
四、数据库的基本管理
4.1数据库的查看

 [root@localhost ~]# mysql -uroot -p
MariaDB [(none)]> SHOW DATABASES;
MariaDB [(none)]>  USE mysql;
MariaDB [mysql]> SHOW TABLES;
MariaDB [mysql]> SELECT * FROM user;
MariaDB [mysql]> SELECT Host,User,Password FROM user;

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
4.2数据库的建立

 MariaDB [mysql]> CREATE DATABASE weel;新建数据库
 MariaDB [mysql]> USE weel;进入数据库
 MariaDB [weel]> CREATE TABLE linux (
    -> usernam varchar (6) not null,
    -> password varchar (30) not null
    -> );    建立表格并设置格式

MariaDB [weel]> DESC linux;  查看表格结构
ariaDB [weel]> INSERT INTO linux VALUES ('user1','123'); 插入数据

在这里插入图片描述
在这里插入图片描述
4.3数据库中表格的更改
注意:直接更改数据库的名称时容易造成数据丢失,需要提前备份数据库才可以更改。
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
4.4删除
在这里插入图片描述
在这里插入图片描述
5、数据库的密码管理
5.1密码的更改
在这里插入图片描述
5.2密码的破解

[root@localhost ~]# systemctl stop mariadb.service 第一步停止服务运行

在这里插入图片描述
在这里插入图片描述

六、用户授权
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

七、数据库的备份

[root@localhost~]# mysqldump -uroot -pwestos --all-database  备份所有数据库内容
[root@calhost ~]# mysqldump -uroot -pwestos --all-database -no-data  备份数据库但是不备份数据库表格的内容,只备份表格结构

在这里插入图片描述

十、phpmyadmin的安装
10.1安装相关服务软件

[root@localhost ~]# dnf install httpd -y
[root@localhost ~]# systemctl enable --now httpd
[root@localhost ~]# dnf install php -y
[root@localhost ~]#dnf install php-mysqlnd -y

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

[root@localhost mysqladmin]# cp config.sample.inc.php  config.inc.php 
[root@localhost mysqladmin]# vim config.inc.php 

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

发布了46 篇原创文章 · 获赞 6 · 访问量 1340

猜你喜欢

转载自blog.csdn.net/qq_46089299/article/details/104816661