Ubuntu 安装 Mysql 5.7(非apt方式安装)

Ubuntu 安装 Mysql 5.7(非apt方式安装),使用在线安装模式

1、下载deb文件并配置

如果你选择下载mysql-apt-config_0.8.xx-1.all.deb文件,到这里下载,选择一个版本,然后下载到ubuntu中,然后就可以dpkg -i运行,进行配置mysql-server的源。

安装记录如下

root@zgk-Ubuntu-T01:~# wget https://repo.mysql.com//mysql-apt-config_0.8.12-1_all.deb
--2022-12-09 17:05:27--  https://repo.mysql.com//mysql-apt-config_0.8.12-1_all.deb
正在解析主机 repo.mysql.com (repo.mysql.com)... 96.16.68.238
正在连接 repo.mysql.com (repo.mysql.com)|96.16.68.238|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度: 36306 (35K) [application/x-debian-package]
正在保存至: “mysql-apt-config_0.8.12-1_all.deb”
 
mysql-apt-config_0.8.1 100%[=========================>]  35.46K   187KB/s    用时 0.2s  
 
2022-12-09 17:05:28 (187 KB/s) - 已保存 “mysql-apt-config_0.8.12-1_all.deb” [36306/36306])
 
root@zgk-Ubuntu-T01:~# sudo dpkg -i mysql-apt-config_0.8.12-1_all.deb 
正在选中未选择的软件包 mysql-apt-config。
(正在读取数据库 ... 系统当前共安装有 187436 个文件和目录。)
准备解压 mysql-apt-config_0.8.12-1_all.deb  ...
正在解压 mysql-apt-config (0.8.12-1) ...
正在设置 mysql-apt-config (0.8.12-1) ...
 

执行这一步最好在机器上运行,在终端工具上,有可能显示不了选项,我使用xshell可以正常。 这个弹出框里,我选择的是“ubuntu bionic”。

之后单击“确定”选项,进入下一个选项,此处默认为第一项,我们在第一项上,回车。

 

 

在出来的选项中,我们就可以选择mysql-5.7了,在“mysq-5.7”上回车。

回车后,系统自动显示我们选择的5.7的选项,通过键盘,选择“ok”,然后回车确定。

 

配置结束后,运行update更新。

root@JfdbSlave:~# apt update
Get:1 http://repo.mysql.com/apt/ubuntu bionic InRelease [20.0 kB]
Err:1 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
Hit:2 http://archive.ubuntu.com/ubuntu jammy InRelease
Get:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease [119 kB]
Get:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease [108 kB]
Get:5 http://archive.ubuntu.com/ubuntu jammy-security InRelease [110 kB]
Reading package lists... Done     
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.

 这里发现了错误,看是因为没有没有公钥,因此我们最好安装公钥。

 

root@JfdbSlave:~# sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 467B942D3A79BD29
Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).
Executing: /tmp/apt-key-gpghome.W5nS9A5Z3V/gpg.1.sh --keyserver keyserver.ubuntu.com --recv-keys 467B942D3A79BD29
gpg: key 467B942D3A79BD29: public key "MySQL Release Engineering <mysql-build@oss.oracle.com>" imported
gpg: Total number processed: 1
gpg:               imported: 1

安装完公钥后再执行  update

这里就执行成功啦。 

2、安装mysq-5.7

此时,在/etc/apt/source.list.d/目录下生成mysql.list,更新完成,我们通过apt-cache policy mysql-server可以查看到,系统中出现了mysql5.7的源。

root@JfdbSlave:~# apt-cache policy mysql-server
mysql-server:
  Installed: (none)
  Candidate: 8.0.33-0ubuntu0.22.04.2
  Version table:
     8.0.33-0ubuntu0.22.04.2 500
        500 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 Packages
        500 http://archive.ubuntu.com/ubuntu jammy-security/main amd64 Packages
     8.0.28-0ubuntu4 500
        500 http://archive.ubuntu.com/ubuntu jammy/main amd64 Packages
     5.7.42-1ubuntu18.04 500
        500 http://repo.mysql.com/apt/ubuntu bionic/mysql-5.7 amd64 Packages

2.1安装mysql-client

这里安装得版本要和上一步查到的源的版本一致,否则找不到辣

apt install mysql-client=5.7.42-1ubuntu18.04
root@JfdbSlave:~# apt install mysql-client=5.7.42-1ubuntu18.04
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  libtinfo5 mysql-common mysql-community-client
The following NEW packages will be installed:
  libtinfo5 mysql-client mysql-common mysql-community-client
0 upgraded, 4 newly installed, 0 to remove and 66 not upgraded.
Need to get 15.4 MB of archives.
After this operation, 99.0 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://repo.mysql.com/apt/ubuntu bionic/mysql-5.7 amd64 mysql-community-client amd64 5.7.42-1ubuntu18.04 [15.3 MB]
Get:2 http://archive.ubuntu.com/ubuntu jammy-updates/universe amd64 libtinfo5 amd64 6.3-2ubuntu0.1 [100 kB]
Get:3 http://repo.mysql.com/apt/ubuntu bionic/mysql-5.7 amd64 mysql-client amd64 5.7.42-1ubuntu18.04 [69.8 kB]                                                                                                                             
Get:4 http://archive.ubuntu.com/ubuntu jammy/main amd64 mysql-common all 5.8+1.0.8 [7,212 B]                                                                                                                                               
Fetched 15.4 MB in 8s (1,915 kB/s)                                                                                                                                                                                                         
Selecting previously unselected package libtinfo5:amd64.
(Reading database ... 74469 files and directories currently installed.)
Preparing to unpack .../libtinfo5_6.3-2ubuntu0.1_amd64.deb ...

Progress: [  0%] [......................................................................................................................................................................................................................] 
Unpacking libtinfo5:amd64 (6.3-2ubuntu0.1) .............................................................................................................................................................................................] 

Selecting previously unselected package mysql-common....................................................................................................................................................................................] 
Preparing to unpack .../mysql-common_5.8+1.0.8_all.deb ...

Unpacking mysql-common (5.8+1.0.8) ...#################.................................................................................................................................................................................] 

Selecting previously unselected package mysql-community-client.#####....................................................................................................................................................................] 
Preparing to unpack .../mysql-community-client_5.7.42-1ubuntu18.04_amd64.deb ...

Unpacking mysql-community-client (5.7.42-1ubuntu18.04) ...######################........................................................................................................................................................] 

Selecting previously unselected package mysql-client.########################################...........................................................................................................................................] 
Preparing to unpack .../mysql-client_5.7.42-1ubuntu18.04_amd64.deb ...

Unpacking mysql-client (5.7.42-1ubuntu18.04) ...##########################################################..............................................................................................................................] 

Setting up mysql-common (5.8+1.0.8) ...###############################################################################..................................................................................................................] 

update-alternatives: using /etc/mysql/my.cnf.fallback to provide /etc/mysql/my.cnf (my.cnf) in auto mode###########################.....................................................................................................] 

Setting up libtinfo5:amd64 (6.3-2ubuntu0.1) ...################################################################################################.........................................................................................] 

Progress: [ 65%] [##########################################################################################################################################............................................................................] 
Setting up mysql-community-client (5.7.42-1ubuntu18.04) ...##############################################################################################################...............................................................] 

Progress: [ 76%] [###################################################################################################################################################################...................................................] 
Setting up mysql-client (5.7.42-1ubuntu18.04) ...#################################################################################################################################################......................................] 

Progress: [ 88%] [############################################################################################################################################################################################..........................] 
Processing triggers for man-db (2.10.2-1) ...##############################################################################################################################################################################.............] 
Processing triggers for libc-bin (2.35-0ubuntu3.1) ...
Scanning processes...                                                                                                                                                                                                                       
Scanning linux images...                                                                                                                                                                                                                    

Running kernel seems to be up-to-date.

No services need to be restarted.

No containers need to be restarted.

No user sessions are running outdated binaries.

No VM guests are running outdated hypervisor (qemu) binaries on this host.

2.2安装mysql-community-server

apt install mysql-community-server=5.7.42-1ubuntu18.04

这个安装完成后,会弹出来框框填写密码 

root@JfdbSlave:~# apt install mysql-community-server=5.7.42-1ubuntu18.04
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  libmecab2
The following NEW packages will be installed:
  libmecab2 mysql-community-server
0 upgraded, 2 newly installed, 0 to remove and 67 not upgraded.
Need to get 40.0 MB of archives.
After this operation, 228 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://archive.ubuntu.com/ubuntu jammy/main amd64 libmecab2 amd64 0.996-14build9 [199 kB]
Get:2 http://repo.mysql.com/apt/ubuntu bionic/mysql-5.7 amd64 mysql-community-server amd64 5.7.42-1ubuntu18.04 [39.8 MB]
Fetched 40.0 MB in 25s (1,605 kB/s)                                                                                                                                                                                                        
Preconfiguring packages ...
Selecting previously unselected package libmecab2:amd64.
(Reading database ... 74554 files and directories currently installed.)
Preparing to unpack .../libmecab2_0.996-14build9_amd64.deb ...

Progress: [  0%] [......................................................................................................................................................................................................................] 
Unpacking libmecab2:amd64 (0.996-14build9) .............................................................................................................................................................................................] 

Selecting previously unselected package mysql-community-server.##.......................................................................................................................................................................] 
Preparing to unpack .../mysql-community-server_5.7.42-1ubuntu18.04_amd64.deb ...

Unpacking mysql-community-server (5.7.42-1ubuntu18.04) ...###############################...............................................................................................................................................] 

Setting up libmecab2:amd64 (0.996-14build9) ...##################################################################.......................................................................................................................] 

Progress: [ 56%] [######################################################################################################################................................................................................................] 
Setting up mysql-community-server (5.7.42-1ubuntu18.04) ...#####################################################################################################........................................................................] 

update-alternatives: using /etc/mysql/mysql.cnf to provide /etc/mysql/my.cnf (my.cnf) in auto mode######################################################################################................................................] 
Created symlink /etc/systemd/system/multi-user.target.wants/mysql.service → /lib/systemd/system/mysql.service.

Processing triggers for man-db (2.10.2-1) ...###################################################################################################################################################################........................] 
Processing triggers for libc-bin (2.35-0ubuntu3.1) ...
Scanning processes...                                                                                                                                                                                                                       
Scanning linux images...                                                                                                                                                                                                                    

Running kernel seems to be up-to-date.

No services need to be restarted.

No containers need to be restarted.

No user sessions are running outdated binaries.

No VM guests are running outdated hypervisor (qemu) binaries on this host.

填完直接回车就好 

 2.3安装mysql-server

apt install mysql-server=5.7.42-1ubuntu18.04
root@JfdbSlave:~# apt install mysql-server=5.7.42-1ubuntu18.04
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
  mysql-server
0 upgraded, 1 newly installed, 0 to remove and 67 not upgraded.
Need to get 69.8 kB of archives.
After this operation, 79.9 kB of additional disk space will be used.
Get:1 http://repo.mysql.com/apt/ubuntu bionic/mysql-5.7 amd64 mysql-server amd64 5.7.42-1ubuntu18.04 [69.8 kB]
Fetched 69.8 kB in 1s (67.4 kB/s)       
Selecting previously unselected package mysql-server.
(Reading database ... 74722 files and directories currently installed.)
Preparing to unpack .../mysql-server_5.7.42-1ubuntu18.04_amd64.deb ...

Progress: [  0%] [......................................................................................................................................................................................................................] 
Unpacking mysql-server (5.7.42-1ubuntu18.04) ...############............................................................................................................................................................................] 

Setting up mysql-server (5.7.42-1ubuntu18.04) ...######################################################.................................................................................................................................] 

Progress: [ 60%] [################################################################################################################################......................................................................................] 
Scanning processes...                                                                                                                                                                                                                       
Scanning linux images...                                                                                                                                                                                                                    

Running kernel seems to be up-to-date.

No services need to be restarted.

No containers need to be restarted.

No user sessions are running outdated binaries.

No VM guests are running outdated hypervisor (qemu) binaries on this host.

这里就安装完成了。

 

安装完成后,通过“dpkg -l | grep mysql”命令可以看到mysql的版本为5.7.42

扩展 : 设置远程登陆访问

注释bind-address = 127.0.0.1。

vim /etc/mysql/mysql.conf.d/mysqld.cnf

 

除了注视掉这句话之外,还可以把后面的IP地址修改成允许连接的IP地址。但是,如果只是开发用的数据库,为了方便起见,还是推荐直接注释掉。

从上面的注释中,可以看出,旧版本的MySQL(从一些资料上显示是5.0及其以前的版本)上使用的是skip-networking。所以,善意提醒一下,使用旧版本的小伙伴请注意一下。

2.删除匿名用户

登录进数据库:

代码如下:


> mysql -u root -p


然后,切换到数据库mysql。SQL如下:

代码如下:


use mysql;


然后,删除匿名用户。SQL如下:

代码如下:


delete from user where user='';

3.增加允许远程访问的用户或者允许现有用户的远程访问。

接着上面,删除匿名用户后,给root授予在任意主机(%)访问任意数据库的所有权限。SQL语句如下:

代码如下:


mysql> grant all privileges on *.* to 'root'@'%' identified by '这里替换成你的密码' with grant option;


如果需要指定访问主机,可以把%替换为主机的IP或者主机名。另外,这种方法会在数据库mysql的表user中,增加一条记录。如果不想增加记录,只是想把某个已存在的用户(例如root)修改成允许远程主机访问,则可以使用如下SQL来完成:

代码如下:


update user set host='%' where user='root' and host='localhost';

flush privileges;

4.退出数据库

代码如下:


mysql> exit

在MySQL Shell执行完SQL后,需要退出到Bash执行系统命令,需要执行exit。因为这个太常用也太简单。以下内容就提示“退出”,不再重复列出这个命令。

5.重启数据库

完成上述所有步骤后,需要重启一下数据库,才能让修改的配置生效。执行如下命令重启数据库:

代码如下:


> sudo service mysql restart

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值