NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FORALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READEACH STEP CAREFULLY!
Inordertologinto 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):
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, andto make the installation go a bit smoother. You should remove them before moving into a production environment.
Remove anonymous users? [Y/n] y ... Success!
root 用户一般应该仅允许从本地登录,禁止远程连接:
1 2 3 4 5
Normally, root should only be allowed to connect from'localhost'. This ensures that someone cannot guess atthe root password fromthe network.
Disallow root login remotely? [Y/n] y ... Success!
MariaDB 默认有一个允许任何人访问的数据库 (test),在生产环境下建议删除之:
1 2 3 4 5 6 7 8 9
By default, MariaDB comes with a database named 'test' that anyone can access. This is also intended onlyfor testing, and should be removed before moving into a production environment.
Remove testdatabaseandaccessto it? [Y/n] y - Dropping test database... ... Success! - Removing privilegesontest database... ... Success!
最后重载权限表以应用上面所做的变更:
1 2 3 4 5 6 7 8 9 10 11 12
Reloadingthe privilege tables will ensure that all changes made so far willtake effect immediately.
Reloadprivilege tables now? [Y/n] y ...Success!
Cleaningup...
Alldone! If you've completed all of the above steps, your MariaDB installationshould now be secure.
Thanksfor using MariaDB!
创建用户
经过安装和简单的初始配置之后,我们来尝试连接到 MariaDB server 看看,直接执行:
1
mysql
此时会遇到错误:
1
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
MariaDB [(none)]> USE mysql; MariaDB [mysql]> CREATE USER 'YOUR_SYSTEM_USER'@'localhost' IDENTIFIED BY ''; MariaDB [mysql]> GRANT ALL PRIVILEGES ON *.* TO 'YOUR_SYSTEM_USER'@'localhost'; MariaDB [mysql]> UPDATE user SET plugin='unix_socket' WHERE User='YOUR_SYSTEM_USER'; MariaDB [mysql]> FLUSH PRIVILEGES; MariaDB [mysql]> exit;