Ubuntu下安装MariaDB

本文的初衷仅供自己做备忘笔记, 内容大多从网上搜集和整理, 并非都是自己原创.
参考的来源我会在后面注明, 对于可能遗漏的来源, 还请相关原创作者提醒, 非常感谢.

资料参考:
https://www.cnblogs.com/lzwangshubo/p/9977997.html
https://mariadb.com/kb/en/library/mariadb-package-repository-setup-and-usage/

环境&版本

  • MairaDB 10.1.43
  • Ubuntu 18.04

更新仓库(非必要)

这一步其实不是必须的, 而是MariaDB推荐的. Ubuntu的Repository里的稳定版可能会比较老, 不是社区最新的稳定版. 因此MairaDB提供了更新仓库的脚步.
执行

curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash

这个脚本会设置3个不同的仓库到配置文件中, 包括:

  • MariaDB Repository
  • MariaDB MaxScale Repository
  • MariaDB Tools Repository

安装服务

sudo apt install mariadb-server

这里我曾经使用sudo apt install mariadb-server-10.4进行安装, 然而后续操作时出现了问题, 导致卸载重装了

启动服务

启动mariadb

sudo systemctl start mariadb

允许mariadb自启动

sudo systemctl enable mariadb

初始化配置

这一步很重要

$ sudo 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
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] n //不使用unix_socket authentication
 ... skipping.

You already have your root account protected, so you can safely answer 'n'.

Change the root password? [Y/n] y //设置root密码
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!

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容