centos7安裝mysql5.7(rpm安裝版)
目錄
1.Centos 查看系統版本信息
-
查看版本號
ll /etc/*centos*
cat /etc/centos-release
- 查看操作系統位數
getconf LONG_BIT
2.下載對應版本的mysql的RP-Bundle包
https://downloads.mysql.com/archives/community/
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.18-1.el7.x86_64.rpm-bundle.tar
- 安裝依賴
- 查看linux上是否已經安裝了mysql,有則卸載,一般centos7默認安裝了mariadb,這裏把它卸載
[root@xiuba108 home]# rpm -qa|grep mariadb
[root@xiuba108 home]# rpm -qa|grep mysql
- 卸載
[root@xiuba108 home]# rpm -e --nodeps mariadb*
[root@xiuba108 home]# rpm -e --nodeps mysql*
- 安裝mysql所需要的依賴
[root@xiuba108 home]# yum -y install libaio
[root@xiuba108 home]# yum -y install perl
[root@xiuba108 home]# yum -y install net-tools
- 安裝mysql
- 解壓mysql安裝包
[root@xiuba108 home]# tar mysql-
mysql-5.7.18-1.el7.x86_64.rpm-bundle.tar mysql-connector-java-5.1.38.jar
[root@xiuba108 home]# ll mysql*
- 安裝mysql5.7,按以下安裝順序
[root@xiuba108 home]# rpm -ivh mysql-community-common-5.7.18-1.el7.x86_64.rpm
[root@xiuba108 home]# rpm -ivh mysql-community-libs-5.7.18-1.el7.x86_64.rpm
[root@xiuba108 home]# rpm -ivh mysql-community-client-5.7.18-1.el7.x86_64.rpm
[root@xiuba108 home]# rpm -ivh mysql-community-server-5.7.18-1.el7.x86_64.rpm
- 查看mysql5.7的狀態,沒有啓動則把mysql啓動
[root@xiuba108 ~]# service mysqld status
- 啓動mysql ,active(running)代表啓動成功
[root@xiuba108 ~]# service mysqld start
- 修改密碼
[root@xiuba108 ~]# grep password /var/log/mysqld.log
- 用臨時密碼登錄mysql
update user set authentication_string=password('123456') where user='root';
Flush privileges;
忘記root密碼解決方案
1.關閉MySQL服務器
service mysqld stop
2.使用--skip-grant-tables選項重啓MySQL服務
mysqld --skip-grant-tables --user=mysql &
3.用空密碼的root用戶連接到MySQ,並且更新root口令:
mysql -uroot
MySQL 5.7以下版本:
update mysql.user set password=password('新密碼') where user='root';
MySQL 5.7版本:
update user set authentication_string=password('新密碼') where user='root' ;
4.刷新權限表,使得權限認證重新生效:
flush privileges;
5.重啓MySQL數據庫
service mysqld restart
6.登錄MySQL
mysql -uroot
- mysql 無法啓動
- 可能是mysql.pid文件沒有寫的權限,找到 my.cnf下面的配置路徑.
ll /var/lib/mysql
chown -R mysql:mysql /var/lib/mysql
- 可能進程裏已經存在mysql進程
ps -ef | grep mysql
解決方法:用命令“ps -ef|grep mysqld ”查看是否有mysqld進程,如果有使用“kill -9 進程號”殺死,然後重新啓動mysqld!
- 可能是第二次在機器上安裝mysql,有殘餘數據影響了服務的啓動。
解決方法:去mysql的數據目錄/data看看,如果存在mysql-bin.index,就趕快把它 刪除掉吧,它就是罪魁禍首了。本人就是使用第三條方法解決的 ! - mysql在啓動時沒有指定配置文件時會使用/etc/my.cnf配置文件,請打開這個文件查看在[mysqld]節下有沒有指定數據目錄(datadir)。
解決方法:請在[mysqld]下設置這一行:datadir = /usr/local/mysql/data - skip-federated字段問題
解決方法:檢查一下/etc/my.cnf文件中有沒有沒被註釋掉的skip-federated字段, 如果有就立即註釋掉吧 - 錯誤日誌目錄不存在
解決方法:使用“chown” “chmod”命令賦予mysql所有者及權限 - selinux惹的禍,如果是centos系統,默認會開啓selinux
解決方法:關閉它,打開/etc/selinux/config,把SELINUX=enforcing改爲 SELINUX=disabled後存盤退出重啓機器試試
- 防火牆開啓端口
到這其實mysql已經安裝和配置好,但是centos7的開了防火牆,外面還是訪問不到mysql 的,所以還要開端口3306(或者把防火牆關掉也行,生產環境勿用)
-
關閉防火牆
[root@localhost src]# systemctl stop firewalld
- centos7下安裝mysql5.7完畢