centos7配置mysql
配置了一天,終於自己的虛擬機上的centos7上搭建好了mysql的環境,期間也踩了不少坑,把自己的經歷寫下了,少走一些彎路
一、安裝msql
1.1 下載mysql源安裝包
# wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
1.2 安裝mysql源
# yum localinstall mysql57-community-release-el7-8.noarch.rpm
1.3 檢查是否安裝成功
#yum repolist enabled | grep "mysql.*-community.*"
1.4 安裝mysql
# yum install mysql-community-server
1.5 啓動mysql服務
#service mysqld start
1.6 檢查服務與端口
#netstat -an|grep 3306
#ps aux|grep mysql
1.7開機啓動
#systemctl enable mysqld
#systemctl daemon-reload
二、mysql相關設置
2.1 設置遠程訪問
2.1.1設置root密碼,登錄mysql
#mysql -uroot -p
mysql> set password for root@localhost = password('yourpassword');
我這裏以設置了密碼,可以看到mysql的版本信息
2.1.2 設置可以遠程訪問
mysql> grant all privileges on *.* to root@'%'identified by 'yourpassword';
2.2 開放遠程訪問端口
1.出現遠程連接ERROR 2003 (HY000):Can't connect to MySQL server on'XXXXX'(111) 的問題。
2.採用ping 192.168.126.128測試通過,然而採用talnet 192.168.126.128 3306 卻未聯通。
原因是:centos防火牆關閉端口訪問,開放相應的端口即可
#查看防火牆服務 #service firewalld status #查看防火牆的規則 #firewall-cmd --list-all #添加規則 #firewall-cmd --zone=public --permanent --add-port=3306/tcp
三.測試
採用navicat客戶端測試