grub2.x86_64 1:2.02-0.64.el7.centos grub2-tools.x86_64 1:2.02-0.64.el7.centos
4.下載MySql安裝包
[root@localhost ~]# rpm -ivh http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
或
[root@localhost ~]# rpm -ivh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
5.安裝MySql
[root@localhost ~]# yum install -y mysql-server
或
[root@localhost ~]# yum install mysql-community-server
若是顯示如下內容說明安裝成功
Complete!
6.設置開機啓動Mysql
[root@localhost ~]# systemctl enable mysqld.service
7.檢查是否已經安裝了開機自動啓動
[root@localhost ~]# systemctl list-unit-files | grep mysqld
若是顯示如下內容說明已經完成自動啓動安裝
mysqld.service enabled
8.設置開啓服務
[root@localhost ~]# systemctl start mysqld.service
9.查看MySql默認密碼
[root@localhost ~]# grep 'temporary password' /var/log/mysqld.log
10.登錄MySql,輸入用戶名和密碼
[root@localhost ~]# mysql -uroot -p
11.修改當前用戶密碼
mysql>SET PASSWORD = PASSWORD('Abc123!_');
12.開啓遠程登陸,受權root遠程登陸
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'a123456!' WITH GRANT OPTION;
13.命令當即執行生效
mysql>flush privileges;
其餘功能:
# 檢查而且顯示Apache相關安裝包
[root@localhost ~]# rpm -qa | grep mysql
# 刪除MySql
[root@localhost ~]# yum remove -y mysql mysql mysql-server mysql-libs compat-mysql51
或
[root@localhost ~]# rpm -e mysql-community-libs-5.7.20-1.el7.x86_64 --nodeps
或
[root@localhost ~]# yum -y remove mysql-community-libs-5.7.20-1.el7.x86_64
# 查看MySql相關文件
[root@localhost ~]# find / -name mysql
# 重啓MySql服務
[root@localhost ~]# service mysqld restart
# 查看MySql版本
[root@localhost ~]# yum repolist all | grep mysql
# 查看當前的啓動的 MySQL 版本
[root@localhost ~]# yum repolist enabled | grep mysql
# 經過Yum來安裝MySQL,會自動處理MySQL與其餘組件的依賴關係
[root@localhost ~]# yum install mysql-community-server
# 查看MySQL安裝目錄
[root@localhost ~]# whereis mysql
# 啓動MySQL服務
[root@localhost ~]# systemctl start mysqld
# 查看MySQL服務狀態
[root@localhost ~]# systemctl status mysqld
# 關閉MySQL服務
[root@localhost ~]# systemctl stop mysqld
# 測試MySQL是否安裝成功
[root@localhost ~]# mysql
# 查看MySql默認密碼
[root@localhost ~]# grep 'temporary password' /var/log/mysqld.log
# 查看全部數據庫
mysql>show databases;
# 退出登陸數據庫
mysql>exit;
# 查看全部數據庫用戶
mysql>SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROM mysql.user;