您好,登錄后才能下訂單哦!
本文主要給大家簡單講講CentOS系統如何安裝和配置MariaDB MySQL,相關專業術語大家可以上網查查或者找一些相關書籍補充一下,這里就不涉獵了,我們就直奔主題吧,希望CentOS系統如何安裝和配置MariaDB MySQL這篇文章可以給大家帶來一些實際幫助。
MariaDB MySQL軟件包
以下是三個主要的MariaDB包:
mariadb-5.5.52-1.el7.x86_64 - 這包含幾個MySQL客戶端程序和實用程序。
mariadb-server-5.5.52-1.el7.x86_64 - 這是主要的MariaDB MySQL數據庫云服務器。
mariadb-libs-5.5.52-1.el7.x86_64 - 包含客戶機程序界面所需的共享庫。
# 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云服務器軟件包。
#yum install mariadb-server
此時,在這個云服務器上,已經安裝了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
驗證確保這已經安裝了三個重要的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數據庫云服務器模塊已加載,但尚未啟動。
# 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云服務器,如下:
#systemctl start mariadb
驗證systemctl狀態以確保mariadb數據庫云服務器已成功啟動
# 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.連接并驗證MariaDB Server
使用如下所示的mysql命令使用mysql的root用戶連接到數據庫
# 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命令將顯示默認的mysql數據庫。
MariaDB [(none)]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | +--------------------+
5.執行MariaDB Post Installation步驟
從上方可以看出,默認情況下,安裝不會為MySQL root帳戶分配任何密碼。
要設置mysql root用戶密碼并在數據庫上執行其他安全配置,請執行如下所示的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.
由于這是我們第一次運行此腳本,因此沒有為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帳戶不同。所以,我們在這里設置mysql root帳號的密碼,這與Linux root帳號無關。
Set root password? [Y/n] y New password: Re-enter new password: Password updated successfully! Reloading privilege tables.. ... Success!
作為默認安裝的一部分,mysql安裝匿名用戶,無需真實用戶即可登錄數據庫。所以我們應該刪除這個用戶
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數據庫。所以,保持這個安全是很重要的。此外,我們應該確保來自其他云服務器的遠程客戶端不允許使用此mysql root帳戶進行連接。
相反,只有本地主機(其中安裝了mysql云服務器)可以使用root帳戶進行連接。所以我們應該遠程禁止root登錄。
Disallow root login remotely? [Y/n] y ... Success!
這是默認的測試數據庫,我們應該刪除它。
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.驗證MySQL根訪問
現在,如果您連接到沒有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命令可以看出,測試數據庫現在被刪除了。
MariaDB [(none)]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | +--------------------+
如果要在mysql命令行中傳遞密碼,請在-p選項旁邊指定,如下所示。
# mysql -u root -pMySecurePassword
注意:-p和密碼之間沒有空格。這可能會導致一些混淆,因為我們在-u和username之間有空格。但是,-p和密碼之間沒有空格。
CentOS系統如何安裝和配置MariaDB MySQL就先給大家講到這里,對于其它相關問題大家想要了解的可以持續關注我們的行業資訊。我們的板塊內容每天都會捕捉一些行業新聞及專業知識分享給大家的。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。