IT培訓(xùn)網(wǎng)
IT在線學(xué)習(xí)
MySQL早期由瑞典的MySQL AB開發(fā)與推廣,后來先后被SUN和Oracle公司所收購,成為當(dāng)今最流行的開源數(shù)據(jù)庫。與其他商用數(shù)據(jù)庫比較,MySQL在功能上存在一定程度的不足,但是這并不影響其受歡迎的程度。因為基本功能夠用而且開源免費,可以大大降低運營成本,所以MySQL在世界范圍內(nèi)的大中小型企業(yè)中得到了廣泛的應(yīng)用。MySQL主要用于存儲業(yè)務(wù)過程中產(chǎn)生的各類業(yè)務(wù)數(shù)據(jù)。
(1)前提條件
假設(shè)當(dāng)前CentOS 7已經(jīng)配置好了網(wǎng)絡(luò)或本地yum源,考慮到安全穩(wěn)定性,通常作為服務(wù)器用的Linux普遍采用最小安裝方式,即只安裝必須要用的軟件包,這樣可以節(jié)約系統(tǒng)資源和降低不需要的應(yīng)用程序所攜帶的潛在安全風(fēng)險。MySQL8.0軟件的安裝過程需要用到諸如Perl語言等的一些相關(guān)軟件包。
(2)下載針對CentOS 7的MySQL 8.0 rpm包
下載MySQL的網(wǎng)址是https://www.mysql.com/downloads/,進入頁面后單擊MySQL社區(qū)版鏈接,如下圖所示。
進入頁面后單擊“MySQL Community Server”,如下圖所示。
進入頁面后,操作系統(tǒng)選擇“Red Hat Enterprice Linux/Oracle Linux”,操作系統(tǒng)版本選擇“Red Hat Enterprice Linux 7/Oracle Linux 7 (x86,64-bit)”,如下圖所示。
在當(dāng)前頁面下方可以看到MySQL 8.0對應(yīng)的“rpm bundle”下載鏈接,單擊“Download”即可,如下圖所示。
頁面跳轉(zhuǎn)到如下圖所示頁面,單擊“No thanks, just start my download.”,即可開始下載MySQL 8.0 rpm包安裝程序。
(3)安裝步驟
①輸入setenforce 0,禁用selinux。通常MySQL運行時需要禁用selinux功能,否則可能會影響MySQL數(shù)據(jù)庫服務(wù)的正常運行。
②上傳MySQL軟件包到CentOS 7系統(tǒng)。通常使用root用戶操作,使用rz命令,將MySQL 8.0 rpm軟件安裝包mysql-8.0.19-1.el7.x86_64.rpm-bundle.tar上傳到CentOS 7的/root目錄中。
③輸入tar -xvf mysql-8.0.19-1.el7.x86_64.rpm-bundle.tar,還原安裝包中的rpm包。
④輸入yum install mysql-community-{libs,client,common,server}-*.rpm,安裝軟件。
⑤輸入systemctl start mysqld,啟動mysql數(shù)據(jù)庫初始化。
(4)首次登錄準備工作
至此,MySQL的軟件已經(jīng)安裝完畢,然后需要啟動MySQL服務(wù),進行數(shù)據(jù)文件的初始化工作,步驟如下:
①輸入grep -i "temporary password" /var/log/mysqld.log,抓取臨時登錄密碼。
②運行mysql_secure_installation初始化MySQL,會有交互式的輸出如下,參見中文的注釋內(nèi)容:
[root@CentOS7-7 bin]# mysql_secure_installation
Securing the MySQL server deployment.
Enter password for user root: 輸入臨時登錄密碼
The 'validate_password' component is installed on the server.
The subsequent steps will run with the existing configuration
of the component.
Using existing password for root.
Estimated strength of the password: 100
Change the password for root ? ((Press y|Y for Yes, any other key for No) : y 改變root密碼選“y”
New password: 輸入新密碼,要求不少于8位,包括大寫字母、小寫字母、數(shù)字和特殊符號
Re-enter new password: 重新輸入新密碼
Estimated strength of the password: 100
#是否繼續(xù)使用新的密碼,選“y”
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
By default, a MySQL installation has an anonymous user,
allowing anyone to log MySQL 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 a production
environment.
# 去除匿名用戶嗎?選“y”
Remove anonymous users? (Press y|Y for Yes, any other key for No) : 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.
# 不允許root用戶遠程登錄?選“y”
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving a production
environment.
#刪除test數(shù)據(jù)庫嗎?選“y”
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
- 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.
# 重新加載授權(quán)表到內(nèi)存,選“y”
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.
# 至此成功初始化用戶
All done!
[root@CentOS7-7 bin]#
③輸入mysql -uroot -p,然后輸入新的密碼,連接MySQL數(shù)據(jù)庫。成功登錄MySQL數(shù)據(jù)庫后,如下圖所示,可以使用select version();語句查看MySQL版本號。
>>本文地址:http://www.yceu.cn/zhuanye/2021/68018.html
聲明:本站稿件版權(quán)均屬中公教育優(yōu)就業(yè)所有,未經(jīng)許可不得擅自轉(zhuǎn)載。
1 您的年齡
2 您的學(xué)歷
3 您更想做哪個方向的工作?