MySQL早期由瑞典的MySQL AB開發與推廣,后來先后被SUN和Oracle公司所收購,成為當今最流行的開源數據庫。與其他商用數據庫比較,MySQL在功能上存在一定程度的不足,但是這并不影響其受歡迎的程度。因為基本功能夠用而且開源免費,可以大大降低運營成本,所以MySQL在世界范圍內的大中小型企業中得到了廣泛的應用。MySQL主要用于存儲業務過程中產生的各類業務數據。
(1)前提條件
假設當前CentOS 7已經配置好了網絡或本地yum源,考慮到安全穩定性,通常作為服務器用的Linux普遍采用最小安裝方式,即只安裝必須要用的軟件包,這樣可以節約系統資源和降低不需要的應用程序所攜帶的潛在安全風險。MySQL8.0軟件的安裝過程需要用到諸如Perl語言等的一些相關軟件包。
(2)下載針對CentOS 7的MySQL 8.0 rpm包
下載MySQL的網址是https://www.mysql.com/downloads/,進入頁面后單擊MySQL社區版鏈接,如下圖所示。
進入頁面后單擊“MySQL Community Server”,如下圖所示。
進入頁面后,操作系統選擇“Red Hat Enterprice Linux/Oracle Linux”,操作系統版本選擇“Red Hat Enterprice Linux 7/Oracle Linux 7 (x86,64-bit)”,如下圖所示。
在當前頁面下方可以看到MySQL 8.0對應的“rpm bundle”下載鏈接,單擊“Download”即可,如下圖所示。
頁面跳轉到如下圖所示頁面,單擊“No thanks, just start my download.”,即可開始下載MySQL 8.0 rpm包安裝程序。
(3)安裝步驟
①輸入setenforce 0,禁用selinux。通常MySQL運行時需要禁用selinux功能,否則可能會影響MySQL數據庫服務的正常運行。
②上傳MySQL軟件包到CentOS 7系統。通常使用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數據庫初始化。
(4)首次登錄準備工作
至此,MySQL的軟件已經安裝完畢,然后需要啟動MySQL服務,進行數據文件的初始化工作,步驟如下:
①輸入grep -i "temporary password" /var/log/mysqld.log,抓取臨時登錄密碼。
②運行mysql_secure_installation初始化MySQL,會有交互式的輸出如下,參見中文的注釋內容:
[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位,包括大寫字母、小寫字母、數字和特殊符號
Re-enter new password: 重新輸入新密碼
Estimated strength of the password: 100
#是否繼續使用新的密碼,選“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數據庫嗎?選“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.
# 重新加載授權表到內存,選“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數據庫。成功登錄MySQL數據庫后,如下圖所示,可以使用select version();語句查看MySQL版本號。
>>本文地址:http://www.028benet.com/zhuanye/2021/68018.html
聲明:本站稿件版權均屬中公教育優就業所有,未經許可不得擅自轉載。
1 您的年齡
2 您的學歷
3 您更想做哪個方向的工作?