MariaDB 是MySQL的一个分支,从MySQL被甲骨文收购之后开发的一个替代品,目前全部兼容MySQL。
MariaDB 是一个采用 Maria 存储引擎的 MySQL 分支版本,是由原来MySQL 的作者 Michael Widenius 创办的公司所开发的免费开源的数据库服务器。
由于满MySQL被Oracle收购后的日渐封闭与缓慢的更新,众多Linux发行版逐渐抛弃了这MySQL数据库,而转向了MariaDB
CentOS 7/RHEL7中,默认已经不再提供mysql的安装源,取而代之的是mysql的原开发者另起炉灶开发的mariadb数据库,不仅完全兼容mysql而且比mysql更加强大。
首先安装mariadb
#yum–y install mariadb mariadb-server
拷贝配置文件(注意:如果/etc目录下面默认有一个my.cnf,直接覆盖即可)
cp/usr/share/mysql/my-huge.cnf /etc/my.cnf
启动mariadb服务并开机自动运行
Mariadb数据库仍然默认使用tcp 3306端口。
打开防火墙服务
安装完后,开始设置Mariadb数据库
#/usr/bin/mysql_secure_installation
输入上述命令后,按照提示操作
NOTE: RUNNING ALL PARTS OF THIS SCRIPTIS 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 thecurrent
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password willbe blank,
so you should just press enter here.
Enter current password for root (enter for none): 安装后默认没有root密码,直接回车
OK, successfully used password, moving on...
Setting the root password ensures that nobody can loginto the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] Y
New password: 输入root的新密码
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 accountcreated for
them. This isintended 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 passwordfrom the network.
Disallow root login remotely? [Y/n] 关闭root远程登录 Y
... Success!
By default, MariaDB comes with a database named 'test'that anyone can
access. This isalso intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] 删除test数据库 Y
- Dropping testdatabase...
... Success!
- Removingprivileges on test database...
... Success!
Reloading the privilege tables will ensure that allchanges made so far
will take effect immediately.
Reload privilege tables now? [Y/n] 确定以上所有操作 Y
... Success!
Cleaning up...
All done! Ifyou've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
或执行mysqladmin为MariaDB数据库账户root设置密码
Mariadb安装完毕后,管理员用户是root密码默认为空,可以执行mysqladmin设置账户密码
如何重设管理员账户root的密码
情况1:在已知mariadb数据库的ROOT用户密码的情况下,修改密码的方法:
1、 在SHELL环境下,使用mysqladmin命令设置:mysqladmin –u root –p password “新密码”回车后要求输入旧密码
2、 在MariaDB[(none)]>环境中,使用update命令,直接更新mysql库user表的数据,不过改完之后需要刷新:
update mysql.user set password=password(‘新密码’) where user=’root’;
flush privileges;
注意:mariadb的sql语句要以分号”;”结束
3、 在MariaDB[(none)]>环境中,使用grant命令,修改root用户的授权权限。
grant all on *.* to root@’localhost’ identified by ‘新密码’;
4、 在MariaDB里面,可以使用 set password重置