• centos7 安装与卸载 Mysql 5.7.27(详细完整教程)


    目录

    卸载

    安装


    卸载

    1、关闭MySQL服务

     systemctl stop mysqld
    

    2、使用 rpm 命令查看已安装的安装包 

    [name@VM-20-12-centos mysql1]$ rpm -qa|grep mysql

     3、使用yum卸载安装的mysql

    [name@VM-20-12-centos mysql1]$ sudo yum remove  mysql mysql-server mysql-libs mysql-server

    4、查询剩余的安装包

    [name@VM-20-12-centos mysql1]$ rpm -qa|grep mysql
    

     5、移除掉这些安装包

    1. [name@VM-20-12-centos mysql1]$ sudo rpm -ev mysql-community-release-el7-5.noarch
    2. [name@VM-20-12-centos mysql1]$ sudo rpm -ev mysql-community-common-5.6.51-2.el7.x86_64

     6、检查残余安装包

    [name@VM-20-12-centos mysql1]$ ls
    

    7、删除残余的安装包 

    sudo rm -rf mysql*

    8、继续查找是否还有残留文件

    [name@VM-20-12-centos mysql1]$ sudo find / -name mysql

     9、移除这些残留文件

    1. [name@VM-20-12-centos mysql1]$ sudo rm -rf /etc/selinux/targeted/active/modules/100/mysql
    2. [name@VM-20-12-centos mysql1]$ sudo rm -rf /usr/share/mysql
    3. [name@VM-20-12-centos mysql1]$ sudo rm -rf /var/lib/mysql
    4. [name@VM-20-12-centos mysql1]$ sudo rm -rf /var/lib/mysql/mysql

    10.最后检查 

    1. [name@VM-20-12-centos mysql1]$ rpm -qa|grep mysql
    2. [name@VM-20-12-centos mysql1]$ sudo find / -name mysql
    3. [name@VM-20-12-centos mysql1]$ ls

    安装

    1. 下载 MySQL yum包

    wget http://repo.mysql.com/mysql57-community-release-el7-10.noarch.rpm

    2.安装MySQL源

    [name@VM-20-12-centos mysql1]$ sudo rpm -Uvh mysql57-community-release-el7-10.noarch.rpm

     3.安装MySQL服务端,需要等待一些时间

    [name@VM-20-12-centos mysql1]$ yum -y install mysql-community-server --nogpgcheck
    

    4.启动MySQL 

    [name@VM-20-12-centos mysql1]$ systemctl start mysqld.service

     

    5.检查是否启动成功 

    [name@VM-20-12-centos mysql1]$ systemctl status mysqld.service

     6.获取临时密码,MySQL5.7为root用户随机生成了一个密码

    [name@VM-20-12-centos mysql1]$ sudo grep 'temporary password' /var/log/mysqld.log 

    7.通过临时密码登录MySQL,进行修改密码操作

    [name@VM-20-12-centos mysql1]$ mysql -uroot -p
    

    8.因为MySQL的密码规则需要很复杂,我们一般自己设置的不会设置成这样,所以我们全局修改一下 

    1. mysql> set global validate_password_policy=0;
    2. mysql> set global validate_password_length=1;

    这时候我们就可以自己设置想要的密码了

    mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'yourpassword';
    

     

    9.授权其他机器远程登录 

    1. mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'yourpassword' WITH GRANT
    2. OPTION;
    3. mysql> FLUSH PRIVILEGES;

    10.开启开机自启动

    先退出mysql命令行,然后输入以下命令

    1. [name@VM-20-12-centos mysql1]$ systemctl enable mysqld
    2. [name@VM-20-12-centos mysql1]$ systemctl daemon-reload

     11.设置MySQL的字符集为UTF-8,令其支持中文

    [name@VM-20-12-centos mysql1]$ sudo vim /etc/my.cnf

     改成如下,然后保存

    1. # For advice on how to change settings please see
    2. # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
    3. [mysql]
    4. default-character-set=utf8
    5. [mysqld]
    6. datadir=/var/lib/mysql
    7. socket=/var/lib/mysql/mysql.sock
    8. default-storage-engine=INNODB
    9. character_set_server=utf8
    10. symbolic-links=0
    11. log-error=/var/log/mysqld.log
    12. pid-file=/var/run/mysqld/mysqld.pid

     12.重启一下MySQL,令配置生效

    [name@VM-20-12-centos mysql1]$ service mysqld restart

    13.确保你在终端命令行可以输入中文

    [name@VM-20-12-centos mysql1]$  env |grep LANG
    

    14.数据库的操作 

    1. 1)查看mysql是否启动:service mysqld status
    2. 启动mysql:service mysqld start
    3. 停止mysql:service mysqld stop
    4. 重启mysql:service mysqld restart
    5. 2)查看临时密码:grep password /var/log/mysqld.log

    查看数据库是否服务起来

    [name@VM-20-12-centos mysql1]$ ps ajx | grep mysql
    

    [name@VM-20-12-centos mysql1]$ sudo netstat -nltp
    

    客户端和服务端对应的路径

    到这里就安装成功啦!!!赶快开始数据库的学习吧。 

  • 相关阅读:
    堆排序算法和Topk思想
    spfa求存在负权边的最短路
    风控蓝宝书《消费信用模型 定价、利润与组合》笔记
    3D封装技术发展
    自学设计模式
    FPGA语法相关知识合集
    【Mysql高级篇】MVCC的原理
    Vue3 setup函数的使用
    JAVA----钉钉机器人消息样式,关于PC 端与手机端文字消息样式显示不统一
    【一篇让你学会】Web接口测试工具--Jmeter
  • 原文地址:https://blog.csdn.net/m0_58367586/article/details/127877686