CentOS 7 安装与卸载MySQL 5.7

前端之家收集整理的这篇文章主要介绍了CentOS 7 安装与卸载MySQL 5.7前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

先介绍卸载

防止重装

  • 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

再介绍安装


按照官方的文档进行安装
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 [email protected]‘%‘ 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://www.voidcn.com/article/p-yliokwql-sy.html

作者:MaxZing
链接http://www.jianshu.com/p/e54ff5283f18
來源:简书 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

猜你在找的CentOS相关文章