背景
前不久開始學習部署ambari,在安裝mysql的時候遇到了點問題,現在從網上找了點部署流程記錄下來便於以後安裝mysql。
Centos 7.2 安裝Mysql 5.7.13
首先要安裝yum,如下:
##tar xvf yum-x.x.x.tar .gzcd yum-x.x.xyummain.py install yum
1. 下載mysql的repo來源
CentOS 7.2的yum來源中預設沒有mysql,要先下載mysql的repo來源2. 安裝mysql57-community-release-el7-8.noarch.rpm套件
<span class="hljs-attribute"><span class="hljs-attribute">rpm <span class="hljs-attribute">-ivh mysql57<span class="hljs-attribute">-community<span class="hljs-subst">-release<span class="hljs-number">-el7<span class="hljs-built_in">-<span class="hljs-subst">8.noarch<span class="hljs-subst">.rpm <a href="http://www.php.cn/wiki/125.html" target="_blank">#--nodeps </a>--</span>for</span>ce</span></span></span></span></span></span></span>
#安裝這個套件後,會得到兩個mysql的yum repo來源:/ etc/yum.repos.d/mysql-community.repo和/etc/yum.repos.d/mysql-community-source.repo
3.安裝mysqlyum install mysql-server
4. 啟動mysql服務
查看MySQL服務是否已啟動
service mysqld status
如果未啟動,可以使用下面指令啟動服務
<code class="hljs sql has-numbering">service mysqld start<br/>or<br/>systemctl <span class="hljs-operator"><span class="hljs-keyword">start mysqld</span></span></code>
5. 重設root密碼
可以安全模式修改root登入密碼或用隨機密碼登入修改密碼。下面用隨機密碼方式
- MySQL為root使用者產生的隨機密碼透過mysqld.log檔案可以查找到:
<span class="hljs-keyword"><span class="hljs-string">##grep <span class="hljs-keyword"> 'temporary password' /var/<span class="hljs-keyword">log/mysqld.</span>log</span></span></span>
<span class="hljs-attribute">mysql <span class="hljs-attribute">-u root <span class="hljs-subst">-p mysql<span class="hljs-subst">> Enter password: (輸入剛才查詢到的隨機密碼) mysql<span class="hljs-built_in">> <span class="hljs-string">SET PASSWORD FOR <span class="hljs-string">'root'@<span class="hljs-subst">'localhost'<span class="hljs-string">= <span class="hljs-subst">"Root-123"; mysql</span>> exit</span></span></span></span></span></span></span></span></span>
<span class="hljs-attribute"><span class="hljs-attribute"><span class="hljs-subst"><span class="hljs-number"></span></span></span></span>
用root新密碼登入:
-
-pRootmysql
-u root-123
###如果上面的方式不能修改可以使用下面安全模式修改root:###关闭服务 systemctl stop mysqld.service vi /etc/my.cnf mysqld下面添加skip-grant-tables 保存退出启动服务 systemctl start mysqld.service mysql -u root 不用密码直接回车 use mysql update user set authentication_string=password('Root-123') where User='root' and Host='localhost'; flush privileges; exit; vi /etc/my.cnf 把 skip-grant-tables 一句删除保存退出重启mysql服务 systemctl restart mysqld.service 再次登录即可 mysql -u root -pRoot-123如果进行操作出现下面的提示: You must reset your password using ALTER USER statement before executing this statement. 就再设置一遍密码 set password = password('Root-123');
######6. 開放3306連接埠# ########允許使用使用者名稱root密碼Root-123456從任何主機連接到mysql伺服器###mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Root-123456' WITH GRANT OPTION; mysql>FLUSH PRIVILEGES; mysql>exit;
###############開啟防火牆mysql 3306連接埠的外部訪問#########firewall-cmd --zone=public --add-port=3306/tcp --permanent############firewall-cmd --reload## ##########
<span class="hljs-comment"><span class="hljs-literal"><span class="hljs-comment"><span class="hljs-literal"><span class="hljs-literal"><span class="hljs-comment"><span class="hljs-literal"><span class="hljs-literal"><span class="hljs-comment"><span class="hljs-literal"><span class="hljs-comment"><span class="hljs-literal"><span class="hljs-literal"><span class="hljs-comment"><span class="hljs-comment"><span class="hljs-literal"><span class="hljs-comment"><span class="hljs-literal"><span class="hljs-literal"><span class="hljs-comment"></span></span></span>總結</span></span></span></span></span></span></span></span></span> </span></span></span></span></span></span></span></span>
上面比較詳細地配置了mysql,可以使用systemctl restart mysqld.service啟動後,在查看mysql的狀態使用指令(ps -ef|grep mysql)顯示目前設定和狀態。剛開始學習這塊,還是有很多不懂的地方,希望各位大神指點。
#################### #################以上是如何在Linux系統下安裝 Mysql的詳細內容。更多資訊請關注PHP中文網其他相關文章!

MySQL使用的是GPL許可證。 1)GPL許可證允許自由使用、修改和分發MySQL,但修改後的分發需遵循GPL。 2)商業許可證可避免公開修改,適合需要保密的商業應用。

選擇InnoDB而不是MyISAM的情況包括:1)需要事務支持,2)高並發環境,3)需要高數據一致性;反之,選擇MyISAM的情況包括:1)主要是讀操作,2)不需要事務支持。 InnoDB適合需要高數據一致性和事務處理的應用,如電商平台,而MyISAM適合讀密集型且無需事務的應用,如博客系統。

在MySQL中,外鍵的作用是建立表與表之間的關係,確保數據的一致性和完整性。外鍵通過引用完整性檢查和級聯操作維護數據的有效性,使用時需注意性能優化和避免常見錯誤。

MySQL中有四種主要的索引類型:B-Tree索引、哈希索引、全文索引和空間索引。 1.B-Tree索引適用於範圍查詢、排序和分組,適合在employees表的name列上創建。 2.哈希索引適用於等值查詢,適合在MEMORY存儲引擎的hash_table表的id列上創建。 3.全文索引用於文本搜索,適合在articles表的content列上創建。 4.空間索引用於地理空間查詢,適合在locations表的geom列上創建。

toCreateAnIndexinMysql,usethecReateIndexStatement.1)forasingLecolumn,使用“ createIndexIdx_lastNameEnemployees(lastName); 2)foracompositeIndex,使用“ createIndexIndexIndexIndexIndexDx_nameOmplayees(lastName,firstName,firstName);” 3)forauniqe instex,creationexexexexex,

MySQL和SQLite的主要區別在於設計理念和使用場景:1.MySQL適用於大型應用和企業級解決方案,支持高性能和高並發;2.SQLite適合移動應用和桌面軟件,輕量級且易於嵌入。

MySQL中的索引是數據庫表中一列或多列的有序結構,用於加速數據檢索。 1)索引通過減少掃描數據量提升查詢速度。 2)B-Tree索引利用平衡樹結構,適合範圍查詢和排序。 3)創建索引使用CREATEINDEX語句,如CREATEINDEXidx_customer_idONorders(customer_id)。 4)複合索引可優化多列查詢,如CREATEINDEXidx_customer_orderONorders(customer_id,order_date)。 5)使用EXPLAIN分析查詢計劃,避

在MySQL中使用事務可以確保數據一致性。 1)通過STARTTRANSACTION開始事務,執行SQL操作後用COMMIT提交或ROLLBACK回滾。 2)使用SAVEPOINT可以設置保存點,允許部分回滾。 3)性能優化建議包括縮短事務時間、避免大規模查詢和合理使用隔離級別。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

SecLists
SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。

SublimeText3 英文版
推薦:為Win版本,支援程式碼提示!

Atom編輯器mac版下載
最受歡迎的的開源編輯器

禪工作室 13.0.1
強大的PHP整合開發環境