Ubuntu 15.10/16.04 安装 MariaDB 没有root密码的问题

MariaDB 数据库管理系统是 MySQL 的一个分支,主要由开源社区在维护,采用 GPL 授权许可。开发这个分支的原因之一是:甲骨文公司收购了 MySQL 后,有将 MySQL 闭源的潜在风险,因此社区采用分支的方式来避开这个风险。[4]

MariaDB 的目的是完全兼容MySQL,包括API和命令行,使之能轻松成为 MySQL 的代替品。在存储引擎方面,10.0.9版起使用 XtraDB (名称代号为Aria)来代替 MySQL 的 InnoDB。

MariaDB 由 MySQL 的创始人麦克尔·维德纽斯主导开发,他早前曾以10亿美元的价格,将自己创建的公司 MySQL AB 卖给了 SUN,此后,随着 SUN 被甲骨文收购,MySQL 的所有权也落入 Oracle 的手中。MariaDB 名称来自麦克尔·维德纽斯的女儿玛丽亚(英语:Maria)的名字。

在 Ubuntu 15.10 或 16.04 里,安装时 MariaDB 并没有要求输入 root 密码,导致后续根本不知道 root 密码是什么,安装 MariaDB 时会默认允许匿名(anonymous)的链接,所以链接 MariaDB 时会自动变为 anonymous 用户。

解决这个的办法很简单

如果你不能进入 anonymous 用户的话,首先要删除数据库文件(这里使用移动备份,以备不时之需),删除的命令如下

sudo service mysql stop
sudo mv /var/lib/mysql /var/lib/mysql.bak
sudo mv /etc/mysql /etc/mysql.bak

然后启动 mysql 服务便可进入匿名用户,如果可以进入匿名用户请跳过这一步

其次使用 sudo mysql -u root 链接数据库,之后执行如下代码

use mysql;
update user set plugin='' where User='root';
flush privileges;
\q

这时,数据库已经可以初始化了,然后进行数据库初始化

mysql_secure_installation

这时间,你的数据库就设置完成啦。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] 
 ... 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] 
 ... 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] 
 - Dropping test database...
ERROR 1008 (HY000) at line 1: Can't drop database 'test'; database doesn't exist
 ... Failed!  Not critical, keep moving...
 - 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] 
 ... 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!

然后该干嘛干嘛吧

您可能还喜欢...

发表评论

电子邮件地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据