一 查看linux操作系統(tǒng)版本和系統(tǒng)內(nèi)核版本
[root@nfs_client ~]# cat /etc/redhat-release 查看操作系統(tǒng)版本
CentOS Linux release 7.5.1804 (Core)
[root@nfs_client ~]# uname -r 查看系統(tǒng)內(nèi)核版本
3.10.0-862.el7.x86_64
1、下載地址;https://dev.mysql.com/downloads/mysql/
2、選擇對(duì)應(yīng)的Linux版本和x86/x64進(jìn)行下載
可以選擇 RPM Bundle,下載完記得解壓 tar -xvf xxx.tar
三 卸載舊版本的MySql (沒(méi)有的話,則跳過(guò)此步驟)
1、查看舊版本MySql
rpm -qa |grep mysql
2、逐個(gè)刪除掉舊的組件
進(jìn)行移除操作,移除的時(shí)候可能會(huì)有依賴,要注意一定的順序。
rpm -e --nodeps {-file-name}
rpm -e --nodeps mysql-community-libs-5.6.35-2.el6.x86_64
// 查看是否還有依賴
rpm -qa |grep mysql
清除一下依賴
yum remove mysql-libs
四 使用 rpm 命令安裝MySql組件
使用命令rpm -ivh {-file-name}進(jìn)行安裝操作。
按照依賴關(guān)系依次安裝rpm包 依賴關(guān)系依次為:
common→libs→client→server
rpm -ivh mysql-community-common-5.7.27-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.27-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.27-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.27-1.el7.x86_64.rpm
五 登錄并創(chuàng)建MySql密碼
1 啟動(dòng)MySql
安裝完后,使用命令 service mysqld start 或 systemctl start mysqld.service 啟動(dòng)MySQL服務(wù)。(如果mysql服務(wù)無(wú)法啟動(dòng),就重啟一下系統(tǒng))
systemctl start mysqld.service 啟動(dòng)mysql
systemctl status mysqld.service 查看mysql狀態(tài)
systemctl stop mysqld.service 關(guān)閉mysql
查看mysql進(jìn)程 ps -ef|grep mysql
查看3306端口 netstat -anop|grep 3306
2 登陸mysql修改root密碼
MySQL5.7.4之前的版本中默認(rèn)是沒(méi)有密碼的
grep 'temporary password' /var/log/mysqld.log
mysql> alter user root@localhost identified by 'sdbrk';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
或
mysql> set password for root@localhost=password('sdbrk');
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
* P.s
提示
如果沒(méi)有找到密碼。可能是之前殘留的數(shù)據(jù)影響了
rm -rf /var/lib/mysql
systemctl restart mysqld
grep 'temporary password' /var/log/mysqld.log
在5.6后,mysql內(nèi)置密碼增強(qiáng)機(jī)制,低強(qiáng)度密碼會(huì)報(bào)錯(cuò):
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
修改步驟:
step1: 更改策略,設(shè)置 validate_password_policy=0;
mysql> set global validate_password_policy=0; # 此時(shí),新密碼長(zhǎng)度大于等于8位才有效,否則報(bào)錯(cuò)
修改有效密碼長(zhǎng)度:
mysql> set global validate_password_length=1;
Query OK, 0 rows affected (0.00 sec)
不管設(shè)置 validate_password_length=1,還是2,3,4 ,‘使密碼長(zhǎng)度生效’這個(gè)參數(shù)的實(shí)際值都是4。超過(guò)4后設(shè)置是多少實(shí)際就是多少。
step2:重設(shè)密碼:
mysql> set password for root@localhost=password('9527');
Query OK, 0 rows affected, 1 warning (0.00 sec)
六 授權(quán)
授予root用戶遠(yuǎn)程訪問(wèn)權(quán)限。
查看當(dāng)前授予過(guò)的權(quán)限:
mysql> use mysql;
Reading table information for completion of table and column names
// 查看user 的可用域
mysql> select user,host from user;
+---------------+-----------+
| user | host |
+---------------+-----------+
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+---------------+-----------+
// 查看授權(quán)
mysql> show grants;
+---------------------------------------------------------------------+
| Grants for root@localhost |
+---------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION |
| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION |
2 rows in set (0.00 sec)
注意:mysql默認(rèn)會(huì)包含四個(gè)數(shù)據(jù)庫(kù),千萬(wàn)不能刪
step3: 授予root用戶遠(yuǎn)程訪問(wèn)權(quán)限:
mysql> grant all privileges on *.* to root@'%' identified by 'Comtop*88';
Query OK, 0 rows affected, 1 warning (0.05 sec)
step4: 刷新權(quán)限
mysql> flush privileges;
Query OK, 0 rows affected (0.36 sec)