美文网首页
MySQL安装,通过apt指定版本

MySQL安装,通过apt指定版本

作者: 黑铁大魔王 | 来源:发表于2023-07-10 17:59 被阅读0次

    ubuntu是18.04(20,22也适用),如果通过apt直接安装,如

    apt-get install mysql
    

    那么安装的mysql版本是apt源里的版本,不一定是我们想要的,或者客户指定的版本。那么解决方案有两个
    第一:在类unix系统上通吃的,源码安装,过程稍微复杂一点,遇到的问题也会稍微多一点。
    第二:通过修改apt中mysql源版本号,使用apt安装。
    本文只讲第二种方式。第一种通过源码编译安装请看这里:ubuntu与mac系统都实践过很多次,好使Ubuntu 18.04,源码安装MySQL5.7.x

    1 - Download and install MySQL server and client

    Since Ubuntu 20.04 used in this guide only has MySQL 8.0 in the APT repository, we need to add MySQL 5.7 repository first before installing it.

    Step 1: Add the MySQL 5.7 APT Repository

    1.1 Download the MySQL repository by executing the following command:

    wget https://dev.mysql.com/get/mysql-apt-config_0.8.12-1_all.deb
    
    image.png

    1.2 After the MySQL package has been successfully downloaded, install it:

    sudo dpkg -i mysql-apt-config_0.8.12-1_all.deb
    
    image.png

    1.3 Next, select Ubuntu Bionic.
    装完了就没有图了,反正把mysql修改成5.7即可,有些系统还需要修改ubuntu bionic

    After that, select the MySQL Server & Cluster option. Then, select mysql-5.7 and finally select Ok.

    1.4 Next, update the APT repository:

    sudo apt update
    
    image.png

    显然这里update失败了,那么来修复

    Note
    If you encounter the "signature couldn't be verified" error like this one: NO_PUBKEY 467B942D3A79BD29, you will need to import the missing gpg key by running the following command:

    sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 467B942D3A79BD29
    
    image.png

    1.5 Then execute the apt update again:

    sudo apt update
    

    To check whether MySQL 5.7 repository has been successfully installed, execute:

    sudo apt-cache policy mysql-server
    

    You should see MySQL 5.7 repository at the bottom of the list.

    image.png
    Step 2: Install MySQL 5.7

    2.1 Now that you have a MySQL 5.7 repository in your system, you can proceed to install it. For this, run the following command:

    sudo apt install -f mysql-client=5.7* mysql-community-server=5.7* mysql-server=5.7*
    

    这个过程可能会出错:

    Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution)
    
    

    大概意思是:未设置依赖项。尝试“apt–fix broken install”,不使用包(或指定解决方案)根据问题提示信息,是由于所依赖的包linux-image-4.10.0-35-generic并没有被正确安装导致。linux-image-x.x.x是内核文件,从提示信息上看,应该是升级过程中断导致的问题。
    执行修复命令,并重新执行更新和升级,确保完整修复问题。

    sudo apt --fix-broken install
    sudo apt-get update
    sudo apt-get upgrade
    

    现在可以安装完成了
    再次执行

    sudo apt install -f mysql-client=5.7* mysql-community-server=5.7* mysql-server=5.7*
    
    image.png

    2.2 Press Y to begin the installation and set the root password when asked.

    2 - Secure your MySQL root user account

    Before starting to use MySQL 5.7, you need to secure it first. For this, use the command:

    sudo mysql_secure_installation
    

    Provide a password when asked, and then answer the security questions.
    下面截图是选择密码强度等级,我这里选的是1级,那么就需要按照MEDIUM的规则,数字,英文,大小写,特殊字符都要有,还要穿插。否则会一支提示fail,不要怀疑是安装程序的问题,只是你的密码设置的不满足规则!

    image.png

    接下来还有几个问题,按自己需求回答(yes/no)即可


    image.png

    3 – Check the MySQL version

    Want to make sure that you have installed everything correctly? You can do that by checking your current MySQL version. First, you need to log in to MySQL using the root password you have set earlier.
    现在可以用刚才设置的密码登录root用户了
    mysql -u root -p

    After that, execute the following command:

    SELECT VERSION();
    

    原文让select version();看版本号,不过也没必要,登录后显示的信息里包含了版本号。我登录msyql后的习惯则是show databases;
    You should see your installed MySQL version.


    image.png

    4 - Add MySQL user and set privileges

    。。。。。。后面是增加用户去权限的内容,

    戳这里 >>> MySql 5.7+【创建新用户】以及【授权】

    相关文章

      网友评论

          本文标题:MySQL安装,通过apt指定版本

          本文链接:https://www.haomeiwen.com/subject/fbneudtx.html