MariaDB 采用 Percona 的 XtraDB 存储引擎替代 MySQL 的 InnoDB,XtraDB 完全兼容 InnoDB。
MySQL 与 MariaDB 版本对比:
MySQL 版本MariaDB 版本主要特点5.55.55.6105.710.1通过 gtid 彻底解决主从同步的延迟问题-10.2-10.3在 下载页面,可以查看每个版本的特点。
对于 CentOS7,通过 yum 安装的版本是 5.5,比较老了:
yum -y install mariadb-serverMariaDB 的官方 yum 源在 这里,可用将下面示例中的版本换成适合你的操作系统的最新版本。例如我用的版本是 http://yum.mariadb.org/10.3/centos7-amd64/。
首先,配置 yum 源:
vi /etc/yum.repos.d/mariadb.repo在里面加入如下内容:
[mariadb] name = MariaDB baseurl = http://yum.mariadb.org/10.3/centos7-amd64/ gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1然后,开始安装:
yum -y install mariadb-server在使用 MariaDB 时,命令中可以直接用 mysql 替换 mariadb,例如 systemctl start mariadb 等价于 systemctl start mysql。
启动 MariaDB: systemctl start mariadb 查看服务状态: systemctl status mariadb如果 MariaDB 启动成功,状态中会包括“Active: active (running)”,最后一句话一般是:
Apr 17 14:32:54 VM_157_18_centos systemd[1]: Started MariaDB database server. 设置每次服务器重启时都自动启动数据库: systemctl enable mariadb上面命令的输出跟下面一样时,表示成功执行:
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.MariaDB 包含一个安全脚本,可以改变一些不安全的默认行为,比如远程登录、简单用户设置等。运行安全脚本:
sudo mysql_secure_installation脚本的每一步都会有详细的解释。第一个交互部分需要你提供 root 密码,因为刚安装的 MariaDB 还没有设置密码,这里直接按 ENTER 进入下一步。下一步设置 root 用户密码。后面的可以全部输入 Y 使用 MariaDB 的建议操作。完整命令如下
# 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 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 ... 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!输出类似下面:
mysqladmin Ver 9.0 Distrib 5.5.56-MariaDB, for Linux on x86_64 Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others. Server version 5.5.56-MariaDB Protocol version 10 Connection Localhost via UNIX socket UNIX socket /var/lib/mysql/mysql.sock Uptime: 14 min 59 sec Threads: 1 Questions: 25 Slow queries: 0 Opens: 1 Flush tables: 2 Open tables: 27 Queries per second avg: 0.027以 root 身份登录后,可以执行任何操作:
mysql -u root -p转载于:https://www.cnblogs.com/kika/p/10851680.html
相关资源:CentOS7安装MariaDB