NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACHSTEP CAREFULLY!
Inorderto 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.
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!
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
Reloading the privilege tables will ensure that all changes made so far will take effect immediately.
Reload privilege tables now? [Y/n] y ... Success!
All done! If you've completed allof the above steps, your MariaDB installation should now be secure.
Thanks for using MariaDB!
经过安装和简单的初始配置之后，我们来尝试连接到 MariaDB server 看看，直接执行：
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;