MariaDB資料庫安裝完需要初始化操作
阿新 • • 發佈:2019-01-01
確認MariaDB資料庫軟體程式安裝完畢並啟動成功後請不要立即使用,為了確保資料庫的安全性和正常運轉,咱們需要先進行對資料庫程式初始化操作。
這個過程需要經歷五個步驟,首先需要讓使用者來設定root使用者在資料庫中的密碼值,但需要注意該密碼並非root管理員使用者在系統中的密碼,因此預設密碼值應該為空,直接回車即可。然後設定root使用者在資料庫中的專有密碼,然後是一次刪除匿名帳戶以及進行root管理員帳戶從遠端登陸資料庫,這樣做能夠很有效的保證資料庫上執行業務的安全性,然後是刪除預設的測試資料庫,並取消對其測試資料庫的一系列訪問許可權,最後是重新整理授權表,讓初始化的設定立即生效。
[[email protected]
~]# mysql_secure_installation /usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found 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: 輸入要為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 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(禁止root使用者從遠端登入) ... 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(刪除test資料庫並取消對其的訪問許可權) - 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!
很多生產環境中需要使用站庫分離的技術,因此如果需要讓root管理員帳戶能夠用遠端訪問資料庫時,可在剛剛初始化過程中設定允許root管理員帳戶從遠端訪問的策略,然後再設定防火牆允許對本機mysql服務程式的訪問請求即可:
[[email protected] ~]# firewall-cmd --permanent --add-service=mysqlsuccess[[email protected] ~]# firewall-cmd --reloadsuccess
一切就緒!~快來嘗試初次登陸到您的MariaDB資料庫中吧,分別用-u引數來指定用超級管理員root使用者來登陸,而-p引數作用是驗證該使用者的密碼值:
[[email protected] ~]# mysql -u root -p
Enter password: 此處輸入root使用者在資料庫中的密碼
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 5.5.35-MariaDB MariaDB Server
Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
最不習慣的地方一定是每次執行資料庫命令後都要用;(分號)結尾,這應該也是與Linux命令最顯著的區別的,每條資料庫命令後面都要加上結束符,一定要記住並且慢慢習慣這種設定哦~例如可以嘗試檢視下當前資料庫管理系統都有那些資料庫:
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
3 rows in set (0.01 sec)