• MySQL的卸载与安装


    MySQL的卸载与安装

    环境:Ubuntu20.04

    MySQL版本: 5.7

    注:Ubuntu 20.04 版本系统自带的 MySQL 版本是 8.0,本文给出 5.7 版本的安装教程


    MySQL的彻底卸载

    1、删除mysql的数据文件

    sudo rm /var/lib/mysql/ -R
    
    • 1

    2、删除mysql的配置文件

    sudo rm /etc/mysql/ -R
    
    • 1

    3、删除依赖项,清除残留数据

    sudo apt-get remove mysql-common
    sudo apt-get autoremove --purge mysql-server-8.0
    dpkg -l|grep ^rc|awk '{print$2}'|sudo xargs dpkg -P
    
    • 1
    • 2
    • 3

    4、查看依赖项,看是否删除干净 (如果执行下条命令无任何输出咋删除干净了)

    dpkg --list|grep mysql
    
    • 1

    未卸载干净的情况只需根据依赖名手动卸载即可,如下图:

    在这里插入图片描述


    ubuntu20.04 安装 MySQL5.7

    1、添加MySQL源

    sudo vim /etc/apt/sources.list.d/mysql.list
    
    • 1

    添加以下内容:

    deb http://repo.mysql.com/apt/ubuntu/ bionic mysql-apt-config
    deb http://repo.mysql.com/apt/ubuntu/ bionic mysql-5.7
    deb http://repo.mysql.com/apt/ubuntu/ bionic mysql-tools
    deb-src http://repo.mysql.com/apt/ubuntu/ bionic mysql-5.7
    
    • 1
    • 2
    • 3
    • 4

    2、更新

    sudo apt update
    
    • 1

    更新过程中如果出现如下错误,

    W: GPG error: http://repo.mysql.com/apt/ubuntu bionic InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 467B942D3A79BD29
    E: The repository 'http://repo.mysql.com/apt/ubuntu bionic InRelease' is not signed.
    N: Updating from such a repository can't be done securely, and is therefore disabled by default.
    N: See apt-secure(8) manpage for repository creation and user configuration details.
    
    • 1
    • 2
    • 3
    • 4

    则执行以下命令后,再更新。

    sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 467B942D3A79BD29
    
    • 1

    3、查看版本信息 (确认之前步骤成功)

    此时通过 sudo apt-cache policy mysql-server 查看版本,就能显示5.7.40-1ubuntu18.04

    在这里插入图片描述

    4、安装MySQL

    sudo apt install mysql-client=5.7.40-1ubuntu18.04
    sudo apt install mysql-server=5.7.40-1ubuntu18.04
    
    • 1
    • 2

    5、验证

    在这里插入图片描述

    安装成功…


    初始环境配置

    1、进入数据库设置root账户的密码和权限 (shell)

    sudo mysql
    
    • 1

    2、切换mysql数据库 (mysql)

    use mysql;
    
    • 1

    3、修改root用户密码 (mysql)

    -- 这句话原封不动地执行
    update user set plugin='mysql_native_password' where user='root';
    
    - 这里'密码'的位置设置为你自己的密码
    -- root是用户名不要改
    update user set authentication_string=PASSWORD('密码') where user='root';
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    4、设置远程登录 (mysql)

    设置root账号允许远程登录,默认只允许本地登录
    -- 这里的'密码'要跟上面的密码保持一致
    -- root是用户名,不要改
    GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '密码' WITH GRANT OPTION;
    
    • 1
    • 2
    • 3
    • 4

    5、刷新权限 (mysql)

    FLUSH PRIVILEGES;
    
    • 1

    6、退出数据库 (mysql)

    exit;
    
    • 1

    7、修改配置文件,注释掉绑定地址 (shell)

    sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
    
    • 1

    在这里插入图片描述

    8、重启数据库 (shell)

    sudo service mysql restart
    
    • 1

    9、正常登录 (shell)

    mysql -uroot -p
    输入密码即可
    
    • 1
    • 2

    在这里插入图片描述

  • 相关阅读:
    【MATLAB】三角函数
    这份公众号运营攻略,可以帮你系统地运营好公众号
    神经网络 推荐
    【算法题】反转链表(头插法、C++实现、力扣第206题、剑指offer第24题)
    Java反射获取抽象类方法属性问题讲解
    List of triangle inequalities
    AWS DynamoDB浅析
    Spring Boot项目中使用Logback日志与使用AOP拦截请求日志信息
    JavaScript+css实现的动态生成3D树效果html页面前端源码
    牛客小白月赛77
  • 原文地址:https://blog.csdn.net/qq_40342400/article/details/127813107