W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
相較于MySQL,MariaDB數(shù)據(jù)庫(kù)管理系統(tǒng)有了很多新鮮的擴(kuò)展特性,例如對(duì)微秒級(jí)別的支持、線程池、子查詢優(yōu)化、進(jìn)程報(bào)告等。在配置妥當(dāng)Yum軟件倉(cāng)庫(kù)后,即可安裝部署MariaDB數(shù)據(jù)庫(kù)主程序及服務(wù)端程序了。
在安裝完畢后,記得啟動(dòng)服務(wù)程序,并將其加入到開(kāi)機(jī)啟動(dòng)項(xiàng)中。
[root@linuxprobe ~]# yum install mariadb mariadb-server
Loaded plugins: langpacks, product-id, subscription-manager
………………省略部分輸出信息………………
Installing:
mariadb x86_64 1:5.5.35-3.el7 rhel 8.9 M
mariadb-server x86_64 1:5.5.35-3.el7 rhel 11 M
Installing for dependencies:
perl-Compress-Raw-Bzip2 x86_64 2.061-3.el7 rhel 32 k
perl-Compress-Raw-Zlib x86_64 1:2.061-4.el7 rhel 57 k
perl-DBD-MySQL x86_64 4.023-5.el7 rhel 140 k
perl-DBI x86_64 1.627-4.el7 rhel 802 k
perl-Data-Dumper x86_64 2.145-3.el7 rhel 47 k
perl-IO-Compress noarch 2.061-2.el7 rhel 260 k
perl-Net-Daemon noarch 0.48-5.el7 rhel 51 k
perl-PlRPC noarch 0.2020-14.el7 rhel 36 k
Transaction Summary
================================================================================
Install 2 Packages (+8 Dependent packages)
Total download size: 21 M
Installed size: 107 M
Is this ok [y/d/N]: y
Downloading packages:
--------------------------------------------------------------------------------
Total 82 MB/s | 21 MB 00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
………………省略部分輸出信息………………
Installed:
mariadb.x86_64 1:5.5.35-3.el7 mariadb-server.x86_64 1:5.5.35-3.el7
Dependency Installed:
perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7
perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7
perl-DBD-MySQL.x86_64 0:4.023-5.el7
perl-DBI.x86_64 0:1.627-4.el7
perl-Data-Dumper.x86_64 0:2.145-3.el7
perl-IO-Compress.noarch 0:2.061-2.el7
perl-Net-Daemon.noarch 0:0.48-5.el7
perl-PlRPC.noarch 0:0.2020-14.el7
Complete!
[root@linuxprobe ~]# systemctl start mariadb
[root@linuxprobe ~]# systemctl enable mariadb
ln -s '/usr/lib/systemd/system/mariadb.service' '/etc/systemd/system/multi-user.target.wants/mariadb.service'
在確認(rèn)MariaDB數(shù)據(jù)庫(kù)軟件程序安裝完畢并成功啟動(dòng)后請(qǐng)不要立即使用。為了確保數(shù)據(jù)庫(kù)的安全性和正常運(yùn)轉(zhuǎn),需要先對(duì)數(shù)據(jù)庫(kù)程序進(jìn)行初始化操作。這個(gè)初始化操作涉及下面5個(gè)步驟。
設(shè)置root管理員在數(shù)據(jù)庫(kù)中的密碼值(注意,該密碼并非root管理員在系統(tǒng)中的密碼,這里的密碼值默認(rèn)應(yīng)該為空,可直接按回車鍵)。 設(shè)置root管理員在數(shù)據(jù)庫(kù)中的專有密碼。 隨后刪除匿名賬戶,并使用root管理員從遠(yuǎn)程登錄數(shù)據(jù)庫(kù),以確保數(shù)據(jù)庫(kù)上運(yùn)行的業(yè)務(wù)的安全性。 刪除默認(rèn)的測(cè)試數(shù)據(jù)庫(kù),取消測(cè)試數(shù)據(jù)庫(kù)的一系列訪問(wèn)權(quán)限。 刷新授權(quán)列表,讓初始化的設(shè)定立即生效。 對(duì)于上述數(shù)據(jù)庫(kù)初始化的操作步驟,劉遄老師已經(jīng)在下面的輸出信息旁邊進(jìn)行了簡(jiǎn)單注釋,確保各位讀者更直觀地了解要輸入的內(nèi)容:
[root@linuxprobe ~]# 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): 當(dāng)前數(shù)據(jù)庫(kù)密碼為空,直接按回車鍵
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管理員設(shè)置的數(shù)據(jù)庫(kù)密碼
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管理員從遠(yuǎ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] y(刪除test數(shù)據(jù)庫(kù)并取消對(duì)它的訪問(wèn)權(quán)限)
- 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(刷新授權(quán)表,讓初始化后的設(shè)定立即生效)
... 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!
在很多生產(chǎn)環(huán)境中都需要使用站庫(kù)分離的技術(shù)(即網(wǎng)站和數(shù)據(jù)庫(kù)不在同一個(gè)服務(wù)器上),如果需要讓root管理員遠(yuǎn)程訪問(wèn)數(shù)據(jù)庫(kù),可在上面的初始化操作中設(shè)置策略,以允許root管理員從遠(yuǎn)程訪問(wèn)。然后還需要設(shè)置防火墻,使其放行對(duì)數(shù)據(jù)庫(kù)服務(wù)程序的訪問(wèn)請(qǐng)求,數(shù)據(jù)庫(kù)服務(wù)程序默認(rèn)會(huì)占用3306端口,在防火墻策略中服務(wù)名稱統(tǒng)一叫作mysql:
[root@linuxprobe ~]# firewall-cmd --permanent --add-service=mysql
success
[root@linuxprobe ~]# firewall-cmd --reload
success
一切準(zhǔn)備就緒?,F(xiàn)在我們將首次登錄MariaDB數(shù)據(jù)庫(kù)。其中,-u參數(shù)用來(lái)指定以root管理員的身份登錄,而-p參數(shù)用來(lái)驗(yàn)證該用戶在數(shù)據(jù)庫(kù)中的密碼值。
[root@linuxprobe ~]# mysql -u root -p
Enter password: 此處輸入root管理員在數(shù)據(jù)庫(kù)中的密碼
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)]>
在登錄MariaDB數(shù)據(jù)庫(kù)后執(zhí)行數(shù)據(jù)庫(kù)命令時(shí),都需要在命令后面用分號(hào)(;)結(jié)尾,這也是與Linux命令最顯著的區(qū)別。大家需要慢慢習(xí)慣數(shù)據(jù)庫(kù)命令的這種設(shè)定。下面執(zhí)行如下命令查看數(shù)據(jù)庫(kù)管理系統(tǒng)中當(dāng)前都有哪些數(shù)據(jù)庫(kù):
MariaDB [(none)]> SHOW databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
3 rows in set (0.01 sec)
小試牛刀過(guò)后,接下來(lái)使用數(shù)據(jù)庫(kù)命令將root管理員在數(shù)據(jù)庫(kù)管理系統(tǒng)中的密碼值修改為linuxprobe。這樣退出后再嘗試登錄,如果還堅(jiān)持輸入原先的密碼,則將提示訪問(wèn)失敗。
MariaDB [(none)]> SET password = PASSWORD('linuxprobe');
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> exit
Bye
[root@linuxprobe ~]# mysql -u root -p
Enter password:此處輸入root管理員在數(shù)據(jù)庫(kù)中的新密碼
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: