绑定完请刷新页面
取消
刷新

分享好友

×
取消 复制
Linux 如何安装 MariaDB 数据库?
2022-05-07 15:09:44
作者:w4tch3r
链接:https://www.zhihu.com/question/483911213/answer/2408314570


使用阿里源的yum命令安装
[root@localhost ~]# yum install mariadb-server mariadb -y

注意,使用阿里源安装时,名字和官方的不一样,官方的名字是MariaDB-server、MariaDB-client。而阿里源为mariadb-server、mariadb。注意区分大小写和名称。切换阿里云可以访问阿里巴巴开源镜像站-OPSX镜像站-阿里云开发者社区里面有更换教程。

2.安装好mariadb后,使用以下命令来管理MariaDB服务:

systemctl status mariadb  # 查看状态
systemctl start mariadb  # 启动
systemctl stop mariadb  # 停止
systemctl restart mariadb  # 重启
systemctl enable mariadb  # 设置开机启动
systemctl disable mariadb  # 取消开机启动

3.初始化mariadb,安全配置向导mysql_secure_installation:

a)为root用户设置密码

b)删除匿名账号

c)取消root用户远程登录

d)删除test库和对test库的访问权限

e)刷新授权表使修改生效

[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): #使用enter进入
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 #设置密码
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 #移除匿名用户
 ... 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 #关闭root远程登陆
 ... 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 #删除测试数据库
 - 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  #重新加载权限表
 ... 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.测试登录mysql

[root@localhost ~]# mysql -uroot -p
Enter password:                      #输入密码
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 14
Server version: 5.5.68-MariaDB MariaDB Server

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

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

MariaDB [(none)]>                   #出现这个证明登录成功了

5.登录后查看用户权限

MariaDB [(none)]> select user,host from mysql.user;
+------+-----------+
| user | host      |
+------+-----------+
| root | 127.0.0.1 |
| root | ::1       |
| root | localhost |
+------+-----------+
3 rows in set (0.00 sec)

分享好友

分享这个小栈给你的朋友们,一起进步吧。

MariaDB
创建时间:2022-03-01 11:18:54
MariaDB
展开
订阅须知

• 所有用户可根据关注领域订阅专区或所有专区

• 付费订阅:虚拟交易,一经交易不退款;若特殊情况,可3日内客服咨询

• 专区发布评论属默认订阅所评论专区(除付费小栈外)

技术专家

查看更多
  • itt0918
    专家
戳我,来吐槽~