CentOS7系統(tǒng)安裝mysql數(shù)據(jù)庫方法介紹
1.下載mysql源安裝包
$ wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
2.安裝mysql源
$yum localinstall mysql57-community-release-el7-8.noarch.rpm
3.檢查mysql源是否安裝成功
$yum repolist enabled | grep "mysql.*-community.*"
4.修改yum源【可跳過】
$ vim /etc/yum.repos.d/mysql-community.repo
改變默認(rèn)安裝的mysql版本。比如要安裝5.6版本,將5.7源的enabled=1改成enabled=0。然后再將5.6源的enabled=0改成enabled=1即可。
備注:enabled=1表示即將要安裝的mysql版本,這個文件也可以不修改,默認(rèn)安裝mysql最高版本
5.安裝MySQL
這一步才是真正安裝mysql
$yum install mysql-community-server
6.啟動MySQL服務(wù)并設(shè)置開機啟動
$systemctl start mysqld
$systemctl enable mysqld
$systemctl daemon-reload
7.端口開放
$ firewall-cmd --zone=public --add-port=3306/tcp --permanent
$firewall-cmd --reload
8.修改root本地登錄密碼
1)查看mysql密碼
$grep 'temporary password' /var/log/mysqld.log
2)連接mysql
$mysql -uroot -p
3)修改密碼【注意:后面的分號一定要跟上】
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
或者:
mysql> set password for 'root'@'localhost'=password('MyNewPass4!');
mysql> show variables like '%password%';
9.添加遠(yuǎn)程登錄用戶
mysql> GRANT ALL PRIVILEGES ON *.* TO 'caoxiaobo'@'%' IDENTIFIED BY 'Caoxiaobo0917!' WITH GRANT OPTION;
10.使用客戶端連接測試
備注:這里的用戶名是第9步設(shè)置的caoxiaobo,密碼為:Caoxiaobo0917!