前不久開始學習部署ambari,在安裝mysql的時候遇到了點問題,現在從網上找了點部署流程記錄下來便於以後安裝mysql。
首先要安裝yum,如下:
##tar xvf yum-x.x.x.tar .gzcd yum-x.x.xyummain.py install yum
<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>
yum install mysql-server
查看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>
可以安全模式修改root登入密碼或用隨機密碼登入修改密碼。下面用隨機密碼方式
<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新密碼登入:
mysql
-u root
-123
关闭服务 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中文網其他相關文章!