Centos下安裝mysql

Centos版本 7.0+ MySql版本5.7.19

第一步:下載mysql的rpm包

wget http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

第二步:安裝mysql的rpm包

rpm -ivh mysql57-community-release-el7-11.noarch.rpm

第三步:使用yum安裝mysql

yum install mysql-community-server

第四步:啟動mysql服務(wù)

service mysqld restart

第五步:查看mysql生成的隨機(jī)密碼,復(fù)制密碼

grep "password" /var/log/mysqld.log

第六步:使用密碼登錄本機(jī)mysql服務(wù)器(note:enter the password you copied at the previous)

mysql -uroot -p

第七步:在mysql中更改root登錄密碼(note:如果提示Your password does not satisfy the current policy requirements,只需增加密碼復(fù)雜度即可)

use mysql;
這一塊要尤其注意。在5.1 字段為password 但是5.7之后的版本變?yōu)榱薬uthentication_string。
UPDATE user SET Password = authentication_string(‘newpass’) WHERE user = ‘root’; 
FLUSH PRIVILEGES;

第八步:開啟容許遠(yuǎn)程訪問:

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'your custom password' WITH GRANT OPTION;

第九步:重啟mysql服務(wù)器:

service mysqld restart

設(shè)置以上之后仍然無法遠(yuǎn)程連接時,按照以下步驟分別排查:

1.查看端口監(jiān)聽情況

netstat -tulpen
#如果沒有顯示如下:
#tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      27         121559     13509/mysqld
#證明監(jiān)聽不正確,輸入如下:
vi `find / -name my.conf`
#然后在配置文件末尾添加:
bind-address = 0.0.0.0
#保存后重啟mysql 
service mysqld restart

2.將端口3306加入防火墻:

sudo firewall-cmd --zone=public --permanent --add-service=mysql

3.重啟防火墻:

sudo systemctl restart firewalld
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容