1. 程式人生 > >CentOS 7 安裝與卸載MySQL 5.7

CentOS 7 安裝與卸載MySQL 5.7

下載頁面 set ima oem sdn local www. 獲得 check

先介紹卸載

防止重裝

  • yum方式

    查看yum是否安裝過mysql
    yum list installed mysql*
    

如或顯示了列表,說明系統中有MySQL
技術分享圖片

  • yum卸載
    根據列表上的名字

    yum remove mysql-community-client mysql-community-common mysql-community-libs mysql-community-libs-compat mysql-community-server mysql57-community-release
    rm -rf /var/lib/mysql  
    rm /etc/my.cnf
    
  • rpm查看安裝

    rpm -qa | grep -i mysql
    
  • 技術分享圖片

  • rpm 卸載

    rpm -e mysql57-community-release-el7-9.noarch
    rpm -e mysql-community-server-5.7.17-1.el7.x86_64
    rpm -e mysql-community-libs-5.7.17-1.el7.x86_64
    rpm -e mysql-community-libs-compat-5.7.17-1.el7.x86_64
    rpm -e mysql-community-common-5.7.17-1.el7.x86_64
    rpm -e mysql-community-client-5.7.17-1.el7.x86_64
    cd /var/lib/  
    rm -rf mysql/
    
  • 清除余項

    whereis mysql
    mysql: /usr/bin/mysql /usr/lib64/mysql /usr/local/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz
    #刪除上面的文件夾
    rm -rf /usr/bin/mysql
    


  • 我就省略了

  • 刪除配置

    rm –rf /usr/my.cnf
    rm -rf /root/.mysql_sercret
    

剩余配置檢查

chkconfig --list | grep -i mysql
chkconfig --del mysqld

根據上面的列表,刪除 ,如:mysqld

再介紹安裝

  • 註意
    yum源,阿裏的CentOS7.repo是沒有的,國外源相當慢,做好心理準備。
  • 下載地址
    http://dev.mysql.com/downloads/
    技術分享圖片
    下載頁面

按照官方的文檔進行安裝
http://dev.mysql.com/doc/refman/5.7/en/installing.html
技術分享圖片

http://dev.mysql.com/doc/refman/5.7/en/linux-installation.html


文檔地址:http://dev.mysql.com/doc/refman/5.7/en/linux-installation.html

3是各種安裝方式列表
CentOS用yum安裝相對省事,省去很多配置環節

yum安裝,先要搞到源

wget http://repo.mysql.com/mysql57-community-release-el7-9.noarch.rpm
sudo rpm -ivh mysql57-community-release-el7-9.noarch.rpm

接下來使用yum安裝

更新yum軟件包

yum check-update  

更新系統

yum update

安裝mysql

yum install mysql mysql-server

接下來是漫長的等待。如果中途關機,或者下載掛了,請執行卸載步驟後,再來一次。

完成後

記住要給root上密碼

/usr/local/mysql/bin/mysqld_safe --skip-grant-tables --user=mysql &
systemctl start mysqld
mysql -u root

mysql> update mysql.user set authentication_string=password(‘new_password‘) where user=‘root‘ and Host =‘localhost‘;
mysql> flush privileges;
mysql> quit;

啟動與開放遠程訪問

systemctl start mysqld
mysql -u root -p
+ 授權遠程訪問
use mysql;
grant all privileges  on *.* to root@‘%‘ identified by "root";
FLUSH RIVILEGES;

建議root不要授權遠程訪問,請創建新mysql用戶

編譯安裝

這個略坑,我按照官方文檔安裝,安好了不會配置,唉,吐槽自己太菜!導致沒啟動成功,後來換成了yum安裝
http://dev.mysql.com/doc/refman/5.7/en/installing-source-distribution.html
我還是要把腳本貼出來

#添加mysql用戶
shell> groupadd mysql
shell> useradd -r -g mysql -s /bin/false mysql
shell> rpmbuild --rebuild --clean MySQL-VERSION.src.rpm
#源碼編譯安裝
shell> tar zxvf mysql-VERSION.tar.gz
shell> cd mysql-VERSION
shell> mkdir build
shell> cd build
shell> cmake ..
shell> make
shell> make install
#結束 source-build specific instructions
#權限步驟
shell> cd /usr/local/mysql
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> bin/mysql_install_db --user=mysql    # MySQL 5.7.6執行
shell> bin/mysqld --initialize --user=mysql # MySQL 5.7.6 更高版本執行
shell> bin/mysql_ssl_rsa_setup              # MySQL 5.7.6 更高版本執行
shell> chown -R root .
shell> chown -R mysql data
shell> bin/mysqld_safe --user=mysql &
#配置命令
shell> cp support-files/mysql.server /etc/init.d/mysql.server

大致是以上的安裝腳本,官網上有詳細解釋每一條的作用。可以參照一下。如果安裝失敗,可以參照最上面的卸載教程。
祝你好運。

參考

http://dev.mysql.com/doc/
http://blog.csdn.net/typa01_kk/article/details/49057073

作者:MaxZing
鏈接:http://www.jianshu.com/p/e54ff5283f18
來源:簡書
著作權歸作者所有。商業轉載請聯系作者獲得授權,非商業轉載請註明出處。

CentOS 7 安裝與卸載MySQL 5.7