MariaDB数据库部署

· 数据库介绍

数据库:是指按照某些特定结构来存储数据资料的数据仓库
数据库管理系统:是一种能够对数据库中存放的数据进行建立、修改、删除、查找、维护等操作的软件程序,它通过把计算机中具体的物理数据转换成适合用户理解的抽象逻辑数据,有效地降低数据库管理的技术门槛

· MySQL与MariaDB

MySQL是一款市场占有率非常高的数据库管理系统,技术成熟、配置步骤相对简单,而且具有良好的可扩展性。但是,由于Oracle公司在2009年收购了MySQL的母公司Sun,因此MySQL数据库项目也随之纳入Oracle麾下,逐步演变为保持着开源软件的身份,但又申请了多项商业专利的软件系统

MariaDB由MySQL项目创始者重新研发了一款全新数据库管理系统。该软件当前由开源社区进行维护,是MySQL的分支产品,而且几乎完全兼容MySQL与MySQL具有高度的兼容性,具有库二进制奇偶校验的直接替换功能,与Mysql API和命令均保持一致
MariaDB自带了一个新的存储引擎Aria,用来替代MyISAM,与MySQL一样好用

MariaDB与Mysql数据库管理系统著名LOGO
在这里插入图片描述

· 数据库部署

1.安装MariaDB数据库

MariaDB数据库管理系统相较于MySQL,有很多扩展特性,如对微秒级别的支持、线程池、子查询优化、进程报告等

[root@xiudaochengxian ~]# yum -y install mariadb mariadb-server		#mariadb数据库主程序 
																	#mariadb-server	服务端程序
Complete!

2.重启mariadb服务并加入开机启动项

[root@xiudaochengxian ~]# systemctl restart mariadb
[root@xiudaochengxian ~]# systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.

3.!数据库初始化

在确认MariaDB数据库软件程序安装完毕并成功启动后请不要立即使用
为了确保数据库的安全性和正常运转,需要先对数据库程序进行初始化操作
1:设置root管理员在数据库中的密码值(注意,该密码并非root管理员在系统中的密码,这里
的密码值默认应该为空,可直接按回车键)
2:设置root管理员在数据库中的专有密码
3:删除匿名账户,并使用root管理员从远程登录数据库,以确保数据库上运行的业务的安全性
4:删除默认的测试数据库,取消测试数据库的一系列访问权限
5:刷新授权列表,让初始化的设定立即生效

[root@xiudaochengxian ~]# 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: 				#设置密码(本次使用设置密码是123456)
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!

4.设置防火墙策略

需要设置防火墙,使其放行对数据库服务程序的访问请求,数据库服务程序默认会占用3306端口,在防火墙策略中服务名称统一叫作mysql

[root@xiudaochengxian ~]# firewall-cmd --permanent --add-service=mysql
success
[root@xiudaochengxian ~]# firewall-cmd --reload 
success

5.登录数据库

[root@xiudaochengxian ~]# mysql -u root -p		#-u root 指定root管理员身份登录
												#-p	在下一行验证用户在数据库的密码

Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 5.5.56-MariaDB MariaDB Server

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 

· 数据库常用语句

不区分大小写
在登录MariaDB数据库后执行数据库命令时,都需要在命令后面用分号(;)结尾,这是与Linux命令最显著的区别
可以输入help命令查看MariaDB能做的操作,语句的用法和MySQL一摸一样

登录数据库(root身份)

[root@xiudaochengxian ~]# mysql -u root -p	
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 5.5.56-MariaDB MariaDB Server

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 

查看数据库管理系统中当前都有哪些数据库

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in 
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值