本文主要給大家簡單講講CentOS系統(tǒng)如何安裝和配置MariaDB MySQL,相關(guān)專業(yè)術(shù)語大家可以上網(wǎng)查查或者找一些相關(guān)書籍補(bǔ)充一下,這里就不涉獵了,我們就直奔主題吧,希望CentOS系統(tǒng)如何安裝和配置MariaDB MySQL這篇文章可以給大家?guī)硪恍?shí)際幫助。
成都創(chuàng)新互聯(lián)服務(wù)項目包括長寧網(wǎng)站建設(shè)、長寧網(wǎng)站制作、長寧網(wǎng)頁制作以及長寧網(wǎng)絡(luò)營銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢、行業(yè)經(jīng)驗(yàn)、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機(jī)構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,長寧網(wǎng)站推廣取得了明顯的社會效益與經(jīng)濟(jì)效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到長寧省份的部分城市,未來相信會繼續(xù)擴(kuò)大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!
MariaDB MySQL軟件包
以下是三個主要的MariaDB包:
mariadb-5.5.52-1.el7.x86_64 - 這包含幾個MySQL客戶端程序和實(shí)用程序。
mariadb-server-5.5.52-1.el7.x86_64 - 這是主要的MariaDB MySQL數(shù)據(jù)庫云服務(wù)器。
mariadb-libs-5.5.52-1.el7.x86_64 - 包含客戶機(jī)程序界面所需的共享庫。
# yum info mariadb-server Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: repos-va.psychz.net * extras: linux.cc.lehigh.edu * updates: mirror.us.leaseweb.net Available Packages Name : mariadb-server Arch : x86_64 Epoch : 1 Version : 5.5.52 Release : 1.el7 Size : 11 M Repo : base/7/x86_64
使用yum install安裝如下所示的MariaDB MySQL云服務(wù)器軟件包。
#yum install mariadb-server
此時,在這個云服務(wù)器上,已經(jīng)安裝了mariadb-server以及以下依賴的包。
mariadb-server.x86_64 1:5.5.52-1.el7 mariadb-libs.x86_64 1:5.5.52-1.el7 mariadb.x86_64 1:5.5.52-1.el7 libaio.x86_64 0:0.3.109-13.el7 perl-DBD-MySQL.x86_64 0:4.023-5.el7 perl-DBI.x86_64 0:1.627-4.el7 perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7 perl-Compress-Raw-Zlib.x86_64 1:2.061-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
驗(yàn)證確保這已經(jīng)安裝了三個重要的MariaDB mysql包。
#rpm -qa | grep -i maria mariadb-5.5.52-1.el7.x86_64 mariadb-server-5.5.52-1.el7.x86_64 mariadb-libs-5.5.52-1.el7.x86_64
如下所示,mariadb數(shù)據(jù)庫云服務(wù)器模塊已加載,但尚未啟動。
# systemctl status mariadb ? mariadb.service - MariaDB database server Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor preset: disabled) Active: inactive (dead)
使用systemctl啟動MariaDB mysql云服務(wù)器,如下:
#systemctl start mariadb
驗(yàn)證systemctl狀態(tài)以確保mariadb數(shù)據(jù)庫云服務(wù)器已成功啟動
# systemctl status mariadb ? mariadb.service - MariaDB database server Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor preset: disabled) Active: active (running) since Thu 2017-06-26 18:26:35 UTC; 13s ago Process: 4049 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=0/SUCCESS) Process: 3969 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SUCCESS) Main PID: 4048 (mysqld_safe) CGroup: /system.slice/mariadb.service +-4048 /bin/sh /usr/bin/mysqld_safe --basedir=/usr +-4206 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mariadb/ma... Aug 15 15:20:30 deploy mariadb-prepare-db-dir[3969]: The latest information about MariaDB is available at http://mariadb.org/. Aug 15 15:20:30 deploy mariadb-prepare-db-dir[3969]: You can find additional information about the MySQL part at: Aug 15 15:20:30 deploy mariadb-prepare-db-dir[3969]: http://dev.mysql.com Aug 15 15:20:30 deploy mariadb-prepare-db-dir[3969]: Support MariaDB development by buying support/new features from MariaDB Aug 15 15:20:30 deploy mariadb-prepare-db-dir[3969]: Corporation Ab. You can contact us about this at sales@mariadb.com. Aug 15 15:20:30 deploy mariadb-prepare-db-dir[3969]: Alternatively consider joining our community based development effort: Aug 15 15:20:30 deploy mariadb-prepare-db-dir[3969]: http://mariadb.com/kb/en/contributing-to-the-mariadb-project/ Aug 15 15:20:30 deploy mysqld_safe[4048]: 170601 15:20:33 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'. Aug 15 15:20:30 deploy mysqld_safe[4048]: 170601 15:20:33 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql Aug 15 15:20:35 deploy systemd[1]: Started MariaDB database server.
4.連接并驗(yàn)證MariaDB Server
使用如下所示的mysql命令使用mysql的root用戶連接到數(shù)據(jù)庫
# mysql -u root Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 2 Server version: 5.5.52-MariaDB MariaDB Server Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]>
以下show database命令將顯示默認(rèn)的mysql數(shù)據(jù)庫。
MariaDB [(none)]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | +--------------------+
5.執(zhí)行MariaDB Post Installation步驟
從上方可以看出,默認(rèn)情況下,安裝不會為MySQL root帳戶分配任何密碼。
要設(shè)置mysql root用戶密碼并在數(shù)據(jù)庫上執(zhí)行其他安全配置,請執(zhí)行如下所示的mysql_secure_installation腳本。
# /usr/bin/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.
由于這是我們第一次運(yùn)行此腳本,因此沒有為mysql root帳戶分配密碼。所以,請在這里輸入
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.
在這個階段,說“y”為MySQL根帳戶分配密碼。之后輸入密碼。
請注意,這個mysql root帳戶與linux root帳戶不同。所以,我們在這里設(shè)置mysql root帳號的密碼,這與Linux root帳號無關(guān)。
Set root password? [Y/n] y New password: Re-enter new password: Password updated successfully! Reloading privilege tables.. ... Success!
作為默認(rèn)安裝的一部分,mysql安裝匿名用戶,無需真實(shí)用戶即可登錄數(shù)據(jù)庫。所以我們應(yīng)該刪除這個用戶
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.
可以想像,mysql root帳號將可以訪問所有的mysql數(shù)據(jù)庫。所以,保持這個安全是很重要的。此外,我們應(yīng)該確保來自其他云服務(wù)器的遠(yuǎn)程客戶端不允許使用此mysql root帳戶進(jìn)行連接。
相反,只有本地主機(jī)(其中安裝了mysql云服務(wù)器)可以使用root帳戶進(jìn)行連接。所以我們應(yīng)該遠(yuǎn)程禁止root登錄。
Disallow root login remotely? [Y/n] y ... Success!
這是默認(rèn)的測試數(shù)據(jù)庫,我們應(yīng)該刪除它。
Remove test database and access to it? [Y/n] y - Dropping test database... ... Success! - Removing privileges on test database... ... Success!
在這里輸入y,以確保我們所做的所有更改將立即生效。
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
6.驗(yàn)證MySQL根訪問
現(xiàn)在,如果您連接到?jīng)]有root密碼的Mysql,您將收到以下訪問被拒絕的錯誤消息。
# mysql -u root ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
要指定密碼,請使用-p選項,如下所示。這將提示用戶輸入密碼。
# mysql -u root -p Enter password:
另外,從下面的show databases命令可以看出,測試數(shù)據(jù)庫現(xiàn)在被刪除了。
MariaDB [(none)]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | +--------------------+
如果要在mysql命令行中傳遞密碼,請在-p選項旁邊指定,如下所示。
# mysql -u root -pMySecurePassword
注意:-p和密碼之間沒有空格。這可能會導(dǎo)致一些混淆,因?yàn)槲覀冊?u和username之間有空格。但是,-p和密碼之間沒有空格。
CentOS系統(tǒng)如何安裝和配置MariaDB MySQL就先給大家講到這里,對于其它相關(guān)問題大家想要了解的可以持續(xù)關(guān)注我們的行業(yè)資訊。我們的板塊內(nèi)容每天都會捕捉一些行業(yè)新聞及專業(yè)知識分享給大家的。