首页 > 数据库 >安装 MySQL 5.7

安装 MySQL 5.7

时间:2024-04-13 17:12:30浏览次数:27  
标签:5.7 -- root MySQL apt mysqld mysql 安装 localhost

安装 MySQL 5.7

CentOS

查看系统中是否自带安装 MySQL

[root@localhost ~]# yum list installed | grep mysql
[root@localhost ~]#
[root@node01 ~]# yum list installed | grep mysql
mysql-libs.x86_64     5.1.71-1.el6      @anaconda-CentOS-201311272149.x86_64/6.5
[root@node01 ~]#

如果有安装,执行删除;如果没有跳过下一步

删除系统自带的 MySQL 及其依赖(防止冲突)

[root@node01 ~]# yum -y remove mysql-libs.x86_64
Loaded plugins: fastestmirror
Setting up Remove Process
Resolving Dependencies
--> Running transaction check
---> Package mysql-libs.x86_64 0:5.1.71-1.el6 will be erased
--> Processing Dependency: libmysqlclient.so.16()(64bit) for package: 2:postfix-2.6.6-2.2.el6_1.x86_64
--> Processing Dependency: libmysqlclient.so.16(libmysqlclient_16)(64bit) for package: 2:postfix-2.6.6-2.2.el6_1.x86_64
--> Processing Dependency: mysql-libs for package: 2:postfix-2.6.6-2.2.el6_1.x86_64
--> Running transaction check
---> Package postfix.x86_64 2:2.6.6-2.2.el6_1 will be erased
--> Processing Dependency: /usr/sbin/sendmail for package: cronie-1.4.4-12.el6.x86_64
--> Running transaction check
---> Package cronie.x86_64 0:1.4.4-12.el6 will be erased
--> Processing Dependency: cronie = 1.4.4-12.el6 for package: cronie-anacron-1.4.4-12.el6.x86_64
--> Running transaction check
---> Package cronie-anacron.x86_64 0:1.4.4-12.el6 will be erased
--> Processing Dependency: /etc/cron.d for package: crontabs-1.10-33.el6.noarch
--> Restarting Dependency Resolution with new changes.
--> Running transaction check
---> Package crontabs.noarch 0:1.10-33.el6 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

==============================================================================================
 Package         Arch    Version              Repository                                 Size
==============================================================================================
Removing:
 mysql-libs      x86_64  5.1.71-1.el6         @anaconda-CentOS-201311272149.x86_64/6.5  4.0 M
Removing for dependencies:
 cronie          x86_64  1.4.4-12.el6         @anaconda-CentOS-201311272149.x86_64/6.5  174 k
 cronie-anacron  x86_64  1.4.4-12.el6         @anaconda-CentOS-201311272149.x86_64/6.5   43 k
 crontabs        noarch  1.10-33.el6          @anaconda-CentOS-201311272149.x86_64/6.5  2.4 k
 postfix         x86_64  2:2.6.6-2.2.el6_1    @anaconda-CentOS-201311272149.x86_64/6.5  9.7 M

Transaction Summary
==============================================================================================
Remove        5 Package(s)

Installed size: 14 M
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Erasing    : cronie-anacron-1.4.4-12.el6.x86_64                                         1/5
  Erasing    : crontabs-1.10-33.el6.noarch                                                2/5
  Erasing    : cronie-1.4.4-12.el6.x86_64                                                 3/5
  Erasing    : 2:postfix-2.6.6-2.2.el6_1.x86_64                                           4/5
  Erasing    : mysql-libs-5.1.71-1.el6.x86_64                                             5/5
  Verifying  : crontabs-1.10-33.el6.noarch                                                1/5
  Verifying  : cronie-anacron-1.4.4-12.el6.x86_64                                         2/5
  Verifying  : cronie-1.4.4-12.el6.x86_64                                                 3/5
  Verifying  : 2:postfix-2.6.6-2.2.el6_1.x86_64                                           4/5
  Verifying  : mysql-libs-5.1.71-1.el6.x86_64                                             5/5

Removed:
  mysql-libs.x86_64 0:5.1.71-1.el6

Dependency Removed:
  cronie.x86_64 0:1.4.4-12.el6               cronie-anacron.x86_64 0:1.4.4-12.el6
  crontabs.noarch 0:1.10-33.el6              postfix.x86_64 2:2.6.6-2.2.el6_1

Complete!
[root@node01 ~]#

检查是否有安装 wget

wget --version

如果没有安装

yum install -y wget

给 CentOS 添加 rpm 源

**在 ** MySQL 官网查找较新的源

[root@localhost ~]# wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
--2021-06-01 22:17:11--  https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
Resolving dev.mysql.com (dev.mysql.com)... 137.254.60.11
Connecting to dev.mysql.com (dev.mysql.com)|137.254.60.11|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm [following]
--2021-06-01 22:17:12--  https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm
Resolving repo.mysql.com (repo.mysql.com)... 23.51.209.162
Connecting to repo.mysql.com (repo.mysql.com)|23.51.209.162|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 26024 (25K) [application/x-redhat-package-manager]
Saving to: ‘mysql80-community-release-el7-3.noarch.rpm’

100%[===========================================================================================================>] 26,024      --.-K/s   in 0.08s

2021-06-01 22:17:13 (306 KB/s) - ‘mysql80-community-release-el7-3.noarch.rpm’ saved [26024/26024]

[root@localhost ~]#

安装下载好的 rpm 文件

[root@localhost ~]# yum install -y mysql80-community-release-el7-3.noarch.rpm
Loaded plugins: fastestmirror
Examining mysql80-community-release-el7-3.noarch.rpm: mysql80-community-release-el7-3.noarch
Marking mysql80-community-release-el7-3.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package mysql80-community-release.noarch 0:el7-3 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=====================================================================================================================================================
 Package                                  Arch                  Version                 Repository                                              Size
=====================================================================================================================================================
Installing:
 mysql80-community-release                noarch                el7-3                   /mysql80-community-release-el7-3.noarch                 31 k

Transaction Summary
=====================================================================================================================================================
Install  1 Package

Total size: 31 k
Installed size: 31 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : mysql80-community-release-el7-3.noarch                                                                                            1/1
  Verifying  : mysql80-community-release-el7-3.noarch                                                                                            1/1

Installed:
  mysql80-community-release.noarch 0:el7-3

Complete!
[root@localhost ~]#

安装成功之后,会在下 <span class="ne-text">/etc/yum.repos.d/</span>​ 增加两个文件

[root@localhost ~]# ll /etc/yum.repos.d/
total 44
-rw-r--r--. 1 root root 1572 Dec  1  2016 CentOS-Base.repo
-rw-r--r--. 1 root root 1664 Sep  5  2019 CentOS-Base.repo.backup
-rw-r--r--. 1 root root 1309 Sep  5  2019 CentOS-CR.repo
-rw-r--r--. 1 root root  649 Sep  5  2019 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  314 Sep  5  2019 CentOS-fasttrack.repo
-rw-r--r--. 1 root root  630 Sep  5  2019 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 Sep  5  2019 CentOS-Sources.repo
-rw-r--r--. 1 root root 6639 Sep  5  2019 CentOS-Vault.repo
-rw-r--r--. 1 root root 2076 Apr 25  2019 mysql-community.repo
-rw-r--r--. 1 root root 2108 Apr 25  2019 mysql-community-source.repo
[root@localhost ~]#

修改 mysql-community.repo 文件

修改前:

mysql 8 的 enable = 1,mysql 5.7 的 enable = 0

要安装哪个版本,就将哪个版本对应的 enable 设置为1,其他的设置为0,这里需要将 mysql 5.7 的 enable = 1,mysql 8 的 enable = 0

# Enable to use MySQL 5.7
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

使用 yum 安装 mysql 5.7

[root@localhost ~]# yum install -y mysql-community-server
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
mysql-connectors-community                                                                                                    | 2.6 kB  00:00:00
mysql-tools-community                                                                                                         | 2.6 kB  00:00:00
mysql57-community                                                                                                             | 2.6 kB  00:00:00
(1/3): mysql-connectors-community/x86_64/primary_db                                                                           |  80 kB  00:00:00
(2/3): mysql-tools-community/x86_64/primary_db                                                                                |  88 kB  00:00:00
(3/3): mysql57-community/x86_64/primary_db                                                                                    | 268 kB  00:00:00
Resolving Dependencies

...

Installed:
  mysql-community-libs.x86_64 0:5.7.34-1.el7    mysql-community-libs-compat.x86_64 0:5.7.34-1.el7    mysql-community-server.x86_64 0:5.7.34-1.el7

Dependency Installed:
  mysql-community-client.x86_64 0:5.7.34-1.el7       mysql-community-common.x86_64 0:5.7.34-1.el7       perl.x86_64 4:5.16.3-299.el7_9
  perl-Carp.noarch 0:1.26-244.el7                    perl-Encode.x86_64 0:2.51-7.el7                    perl-Exporter.noarch 0:5.68-3.el7
  perl-File-Path.noarch 0:2.09-2.el7                 perl-File-Temp.noarch 0:0.23.01-3.el7              perl-Filter.x86_64 0:1.49-3.el7
  perl-Getopt-Long.noarch 0:2.40-3.el7               perl-HTTP-Tiny.noarch 0:0.033-3.el7                perl-PathTools.x86_64 0:3.40-5.el7
  perl-Pod-Escapes.noarch 1:1.04-299.el7_9           perl-Pod-Perldoc.noarch 0:3.20-4.el7               perl-Pod-Simple.noarch 1:3.28-4.el7
  perl-Pod-Usage.noarch 0:1.63-3.el7                 perl-Scalar-List-Utils.x86_64 0:1.27-248.el7       perl-Socket.x86_64 0:2.010-5.el7
  perl-Storable.x86_64 0:2.45-3.el7                  perl-Text-ParseWords.noarch 0:3.29-4.el7           perl-Time-HiRes.x86_64 4:1.9725-3.el7
  perl-Time-Local.noarch 0:1.2300-2.el7              perl-constant.noarch 0:1.27-2.el7                  perl-libs.x86_64 4:5.16.3-299.el7_9
  perl-macros.x86_64 4:5.16.3-299.el7_9              perl-parent.noarch 1:0.225-244.el7                 perl-podlators.noarch 0:2.5.1-3.el7
  perl-threads.x86_64 0:1.87-4.el7                   perl-threads-shared.x86_64 0:1.43-6.el7

Dependency Updated:
  postfix.x86_64 2:2.10.1-9.el7

Replaced:
  mariadb-libs.x86_64 1:5.5.64-1.el7

Complete!
[root@localhost ~]#

启动 mysql 服务并设置开机自启动

# 启动服务
[root@localhost ~]# systemctl start mysqld
[root@localhost ~]#

# 设置开机自启动
[root@localhost ~]# systemctl enable mysqld
[root@localhost ~]#

# 检查运行状态
[root@localhost ~]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2021-06-01 22:43:10 CST; 38s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
 Main PID: 10252 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─10252 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

Jun 01 22:43:06 localhost.localdomain systemd[1]: Starting MySQL Server...
Jun 01 22:43:10 localhost.localdomain systemd[1]: Started MySQL Server.
[root@localhost ~]#

获取 mysql 的临时密码

[root@localhost ~]# grep "password" /var/log/mysqld.log
2021-06-01T14:43:07.907876Z 1 [Note] A temporary password is generated for root@localhost: P4d=+xw-VEfY
[root@localhost ~]#

修改 root 密码

  • validate_password_policy

  • 0 or LOW

  • 1 or MEDIUM

  • 2 or STRONG

  • validate_password_length

  • 密码长度的最小值

使用临时密码登录:

[root@localhost ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.34

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
mysql> set global validate_password_policy = 0;
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql> set global validate_password_length = 1;
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql>
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql>

密码验证的相关参数:

mysql> show variables like 'validate_password%';
+--------------------------------------+-------+
| Variable_name                        | Value |
+--------------------------------------+-------+
| validate_password_check_user_name    | OFF   |
| validate_password_dictionary_file    |       |
| validate_password_length             | 4     |
| validate_password_mixed_case_count   | 1     |
| validate_password_number_count       | 1     |
| validate_password_policy             | LOW   |
| validate_password_special_char_count | 1     |
+--------------------------------------+-------+
7 rows in set (0.01 sec)

mysql>
mysql>

授权远程登录

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456';
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql>
mysql>
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql>

设置默认字符集为 utf8mb4

**修改 MySQL 配置文件 ** <span class="ne-text">/etc/my.cnf</span>

[mysqld]
character-set-server=utf8mb4

# 如果没有 [client], 添加 [client] 段
[client]
default-character-set=utf8mb4

重启 MySQL 服务

[root@localhost ~]# systemctl restart mysqld
[root@localhost ~]#

第一次在这里重启的时候,重启失败

[root@localhost ~]# systemctl restart mysqld
Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.
[root@localhost ~]#
[root@localhost ~]# systemctl status mysqld.service
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: failed (Result: start-limit) since Tue 2021-06-01 23:02:17 CST; 35s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 10519 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=1/FAILURE)
  Process: 10500 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 10252 (code=exited, status=0/SUCCESS)

Jun 01 23:02:17 localhost.localdomain systemd[1]: Failed to start MySQL Server.
Jun 01 23:02:17 localhost.localdomain systemd[1]: Unit mysqld.service entered failed state.
Jun 01 23:02:17 localhost.localdomain systemd[1]: mysqld.service failed.
Jun 01 23:02:17 localhost.localdomain systemd[1]: mysqld.service holdoff time over, scheduling restart.
Jun 01 23:02:17 localhost.localdomain systemd[1]: Stopped MySQL Server.
Jun 01 23:02:17 localhost.localdomain systemd[1]: start request repeated too quickly for mysqld.service
Jun 01 23:02:17 localhost.localdomain systemd[1]: Failed to start MySQL Server.
Jun 01 23:02:17 localhost.localdomain systemd[1]: Unit mysqld.service entered failed state.
Jun 01 23:02:17 localhost.localdomain systemd[1]: mysqld.service failed.
[root@localhost ~]#

执行journalctl -xe

Jun 01 23:02:13 localhost.localdomain polkitd[828]: Registered Authentication Agent for unix-process:10399:519107 (system bus name :1.31 [/usr/bin/pk
Jun 01 23:02:13 localhost.localdomain systemd[1]: Stopping MySQL Server...
-- Subject: Unit mysqld.service has begun shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mysqld.service has begun shutting down.
Jun 01 23:02:15 localhost.localdomain systemd[1]: Stopped MySQL Server.
-- Subject: Unit mysqld.service has finished shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mysqld.service has finished shutting down.
Jun 01 23:02:15 localhost.localdomain systemd[1]: Starting MySQL Server...
-- Subject: Unit mysqld.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mysqld.service has begun starting up.
Jun 01 23:02:15 localhost.localdomain mysqld[10424]: mysqld: Character set 'utf8mb4;' is not a compiled character set and is not specified in the '/u
Jun 01 23:02:15 localhost.localdomain mysqld[10424]: 2021-06-01T15:02:15.418020Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Ple
Jun 01 23:02:15 localhost.localdomain mysqld[10424]: 2021-06-01T15:02:15.419186Z 0 [Note] /usr/sbin/mysqld (mysqld 5.7.34) starting as process 10427
Jun 01 23:02:15 localhost.localdomain mysqld[10424]: 2021-06-01T15:02:15.420115Z 0 [ERROR] Aborting
Jun 01 23:02:15 localhost.localdomain mysqld[10424]: 2021-06-01T15:02:15.420155Z 0 [Note] Binlog end
Jun 01 23:02:15 localhost.localdomain mysqld[10424]: 2021-06-01T15:02:15.420214Z 0 [Note] /usr/sbin/mysqld: Shutdown complete
Jun 01 23:02:15 localhost.localdomain systemd[1]: mysqld.service: control process exited, code=exited status=1
Jun 01 23:02:15 localhost.localdomain mysqld[10424]: Initialization of mysqld failed: 0
Jun 01 23:02:15 localhost.localdomain systemd[1]: Failed to start MySQL Server.
-- Subject: Unit mysqld.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mysqld.service has failed.
--
-- The result is failed.
Jun 01 23:02:15 localhost.localdomain systemd[1]: Unit mysqld.service entered failed state.
Jun 01 23:02:15 localhost.localdomain systemd[1]: mysqld.service failed.

注意到有提示:mysqld: Character set 'utf8mb4;' is not a compiled character set and is not specified in the ...

检查 my.cnf 中添加的配置信息,在最后添加了 ;​ 分号,删除后再重启正常

[mysqld]
character-set-server=utf8mb4;

[client]
default-character-set=utf8mb4;
Public key for mysql-community-libs-compat-5.7.39-1.el7.x86_64.rpm is not installed

处理:

rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

Ubuntu

添加 deb 源

**在 ** MySQL 官网查找较新的源

https://dev.mysql.com/get/mysql-apt-config_0.8.24-1_all.deb

安装下载好的 deb 文件

zhpj@localhost:~/software$ sudo apt install -y ./mysql-apt-config_0.8.24-1_all.deb
[sudo] password for zhpj:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Note, selecting 'mysql-apt-config' instead of './mysql-apt-config_0.8.24-1_all.deb'
The following NEW packages will be installed:
  mysql-apt-config
0 upgraded, 1 newly installed, 0 to remove and 34 not upgraded.
Need to get 0 B/18.0 kB of archives.
After this operation, 35.8 kB of additional disk space will be used.
Get:1 /home/zhpj/software/mysql-apt-config_0.8.24-1_all.deb mysql-apt-config all 0.8.24-1 [18.0 kB]
Preconfiguring packages ...
Selecting previously unselected package mysql-apt-config.
(Reading database ... 80211 files and directories currently installed.)
Preparing to unpack .../mysql-apt-config_0.8.24-1_all.deb ...
Unpacking mysql-apt-config (0.8.24-1) ...
Setting up mysql-apt-config (0.8.24-1) ...
Warning: apt-key should not be used in scripts (called from postinst maintainerscript of the package mysql-apt-config)
Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).
OK
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.
N: Download is performed unsandboxed as root as file '/home/zhpj/software/mysql-apt-config_0.8.24-1_all.deb' couldn't be accessed by user '_apt'. - pkgAcquire::Run (13: Permission denied)
zhpj@localhost:~/software$


zhpj@localhost:~/software$ chmod 777 mysql-apt-config_0.8.24-1_all.deb
zhpj@localhost:~/software$
zhpj@localhost:~/software$ sudo apt install -y ./mysql-apt-config_0.8.24-1_all.deb
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Note, selecting 'mysql-apt-config' instead of './mysql-apt-config_0.8.24-1_all.deb'
mysql-apt-config is already the newest version (0.8.24-1).
0 upgraded, 0 newly installed, 0 to remove and 34 not upgraded.
zhpj@localhost:~/software$
zhpj@localhost:~/software$ ll /etc/apt/sources.list.d/
total 12
drwxr-xr-x 2 root root 4096 Apr  7 03:19 ./
drwxr-xr-x 8 root root 4096 Apr  7 03:19 ../
-rw-r--r-- 1 root root  499 Apr  7 03:19 mysql.list
zhpj@localhost:~/software$


zhpj@localhost:~/software$ sudo apt update
Hit:1 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy InRelease
Hit:2 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-updates InRelease
Hit:3 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-backports InRelease
Hit:4 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-security InRelease
Get:5 http://repo.mysql.com/apt/ubuntu jammy InRelease [15.2 kB]
Get:6 http://repo.mysql.com/apt/ubuntu jammy/mysql-apt-config amd64 Packages [565 B]
Get:7 http://repo.mysql.com/apt/ubuntu jammy/mysql-tools amd64 Packages [7,905 B]
Fetched 23.7 kB in 6s (4,234 B/s)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
34 packages can be upgraded. Run 'apt list --upgradable' to see them.
W: http://repo.mysql.com/apt/ubuntu/dists/jammy/InRelease: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details.
zhpj@localhost:~/software$



zhpj@localhost:~/software$ sudo dpkg -i ./mysql-apt-config_0.8.24-1_all.deb
(Reading database ... 80216 files and directories currently installed.)
Preparing to unpack .../mysql-apt-config_0.8.24-1_all.deb ...
Unpacking mysql-apt-config (0.8.24-1) over (0.8.24-1) ...
Setting up mysql-apt-config (0.8.24-1) ...
Warning: apt-key should not be used in scripts (called from postinst maintainerscript of the package mysql-apt-config)
Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).
OK
zhpj@localhost:~/software$
zhpj@localhost:~/software$ sudo apt update
Hit:1 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy InRelease
Hit:2 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-updates InRelease
Hit:3 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-backports InRelease
Hit:4 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-security InRelease
Hit:5 http://repo.mysql.com/apt/ubuntu jammy InRelease
Get:6 http://repo.mysql.com/apt/ubuntu jammy/mysql-8.0 Sources [966 B]
Get:7 http://repo.mysql.com/apt/ubuntu jammy/mysql-8.0 amd64 Packages [8,555 B]
Ign:7 http://repo.mysql.com/apt/ubuntu jammy/mysql-8.0 amd64 Packages
Get:7 http://repo.mysql.com/apt/ubuntu jammy/mysql-8.0 amd64 Packages [8,555 B]
Fetched 6,907 B in 46s (150 B/s)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
34 packages can be upgraded. Run 'apt list --upgradable' to see them.
W: http://repo.mysql.com/apt/ubuntu/dists/jammy/InRelease: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details.
zhpj@localhost:~/software$


sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 8C718D3B5072E1F5


zhpj@localhost:~/software$ sudo apt-key list
Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).
/etc/apt/trusted.gpg
--------------------
pub   rsa4096 2021-12-14 [SC] [expires: 2023-12-14]
      859B E8D7 C586 F538 430B  19C2 467B 942D 3A79 BD29
uid           [ unknown] MySQL Release Engineering <mysql-build@oss.oracle.com>
sub   rsa4096 2021-12-14 [E] [expires: 2023-12-14]

/etc/apt/trusted.gpg.d/ubuntu-keyring-2012-cdimage.gpg
------------------------------------------------------
pub   rsa4096 2012-05-11 [SC]
      8439 38DF 228D 22F7 B374  2BC0 D94A A3F0 EFE2 1092
uid           [ unknown] Ubuntu CD Image Automatic Signing Key (2012) <cdimage@ubuntu.com>

/etc/apt/trusted.gpg.d/ubuntu-keyring-2018-archive.gpg
------------------------------------------------------
pub   rsa4096 2018-09-17 [SC]
      F6EC B376 2474 EDA9 D21B  7022 8719 20D1 991B C93C
uid           [ unknown] Ubuntu Archive Automatic Signing Key (2018) <ftpmaster@ubuntu.com>

zhpj@localhost:~/software$

zhpj@localhost:~/software$ sudo cp /etc/apt/trusted.gpg /etc/apt/trusted.gpg.d/
zhpj@localhost:~/software$
zhpj@localhost:~/software$ sudo apt update
Hit:1 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy InRelease
Hit:2 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-updates InRelease
Hit:3 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-backports InRelease
Hit:4 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-security InRelease
Hit:5 http://repo.mysql.com/apt/ubuntu jammy InRelease
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
34 packages can be upgraded. Run 'apt list --upgradable' to see them.
zhpj@localhost:~/software$



zhpj@localhost:~/software$ cat /etc/apt/sources.list.d/mysql.list
### THIS FILE IS AUTOMATICALLY CONFIGURED ###
# You may comment out entries below, but any other modifications may be lost.
# Use command 'dpkg-reconfigure mysql-apt-config' as root for modifications.
deb http://repo.mysql.com/apt/ubuntu/ jammy mysql-apt-config
deb http://repo.mysql.com/apt/ubuntu/ jammy mysql-8.0
deb http://repo.mysql.com/apt/ubuntu/ jammy mysql-tools
#deb http://repo.mysql.com/apt/ubuntu/ jammy mysql-tools-preview
deb-src http://repo.mysql.com/apt/ubuntu/ jammy mysql-8.0
zhpj@localhost:~/software$


zhpj@localhost:~/software$ sudo vi /etc/apt/sources.list.d/mysql.list
zhpj@localhost:~/software$
zhpj@localhost:~/software$ cat /etc/apt/sources.list.d/mysql.list
### THIS FILE IS AUTOMATICALLY CONFIGURED ###
# You may comment out entries below, but any other modifications may be lost.
# Use command 'dpkg-reconfigure mysql-apt-config' as root for modifications.
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 http://repo.mysql.com/apt/ubuntu/ bionic mysql-tools-preview
deb-src http://repo.mysql.com/apt/ubuntu/ bionic mysql-5.7
zhpj@localhost:~/software$
zhpj@localhost:~/software$ sudo apt update
Hit:1 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy InRelease
Hit:2 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-updates InRelease
Hit:3 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-backports InRelease
Hit:4 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-security InRelease
Get:5 http://repo.mysql.com/apt/ubuntu bionic InRelease [20.0 kB]
Get:6 http://repo.mysql.com/apt/ubuntu bionic/mysql-5.7 Sources [926 B]
Get:7 http://repo.mysql.com/apt/ubuntu bionic/mysql-apt-config amd64 Packages [565 B]
Get:8 http://repo.mysql.com/apt/ubuntu bionic/mysql-5.7 amd64 Packages [5,664 B]
Get:9 http://repo.mysql.com/apt/ubuntu bionic/mysql-tools amd64 Packages [8,267 B]
Fetched 35.5 kB in 1s (29.5 kB/s)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
34 packages can be upgraded. Run 'apt list --upgradable' to see them.
zhpj@localhost:~/software$



zhpj@localhost:~/software$ sudo apt-cache policy mysql-server
mysql-server:
  Installed: (none)
  Candidate: 8.0.32-0ubuntu0.22.04.2
  Version table:
     8.0.32-0ubuntu0.22.04.2 500
        500 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-updates/main amd64 Packages
        500 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-security/main amd64 Packages
     8.0.32-0buntu0.22.04.1 500
        500 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-updates/main amd64 Packages
     8.0.28-0ubuntu4 500
        500 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy/main amd64 Packages
     5.7.41-1ubuntu18.04 500
        500 http://repo.mysql.com/apt/ubuntu bionic/mysql-5.7 amd64 Packages
zhpj@localhost:~/software$


zhpj@localhost:~/software$ sudo apt install -y mysql-client=5.7.41-1ubuntu18.04
zhpj@localhost:~/software$ sudo apt install -y mysql-server=5.7.41-1ubuntu18.04
zhpj@localhost:~/software$ 
zhpj@localhost:~/software$ 
zhpj@localhost:~/software$ mysql --version
mysql  Ver 14.14 Distrib 5.7.41, for Linux (x86_64) using  EditLine wrapper
zhpj@localhost:~/software$

zhpj@localhost:~/software$ systemctl status mysql.service
● mysql.service - MySQL Community Server
     Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2023-04-07 03:54:25 UTC; 38s ago
    Process: 6714 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
    Process: 6764 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid (code=exited, status=0/S>
   Main PID: 6766 (mysqld)
      Tasks: 27 (limit: 4530)
     Memory: 172.1M
        CPU: 379ms
     CGroup: /system.slice/mysql.service
             └─6766 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

Apr 07 03:54:25 localhost systemd[1]: Starting MySQL Community Server...
Apr 07 03:54:25 localhost systemd[1]: Started MySQL Community Server.
zhpj@localhost:~/software$


zhpj@localhost:~/software$ ll /etc/mysql/
total 24
drwxr-xr-x  4 root root 4096 Apr  7 03:56 ./
drwxr-xr-x 99 root root 4096 Apr  7 03:54 ../
drwxr-xr-x  2 root root 4096 Apr  7 03:53 conf.d/
lrwxrwxrwx  1 root root   24 Apr  7 03:54 my.cnf -> /etc/alternatives/my.cnf
-rw-r--r--  1 root root  839 Oct 20  2020 my.cnf.fallback
-rw-r--r--  1 root root 1200 Dec  7 18:24 mysql.cnf
drwxr-xr-x  2 root root 4096 Apr  7 03:54 mysql.conf.d/
zhpj@localhost:~/software$
zhpj@localhost:~/software$ ll /etc/mysql/conf.d/
total 16
drwxr-xr-x 2 root root 4096 Apr  7 03:53 ./
drwxr-xr-x 4 root root 4096 Apr  7 03:56 ../
-rw-r--r-- 1 root root    8 Oct 20  2020 mysql.cnf
-rw-r--r-- 1 root root   55 Oct 20  2020 mysqldump.cnf
zhpj@localhost:~/software$

ubuntu 的参考文章:亲测-ubuntu20.04 安装 MySQL5.7

标签:5.7,--,root,MySQL,apt,mysqld,mysql,安装,localhost
From: https://www.cnblogs.com/zhpj/p/18133077/an-zhuang-mysql-5.7-z1wtozl

相关文章

  • centos6.5安装python3.6.9
    下载python:https://www.python.org/ftp/python/3.6.9/Python-3.6.9.tgz安装tar-zxvfPython-3.6.9.tgzcdPython-3.6.9./configure--prefix=/opt/python3.6makemakeinstallecho"/opt/python3.6/lib">/etc/ld.so.conf.d/python3.6.9.confsudoldconf......
  • 允许任意地址访问 MySQL 数据库 adonis 的新用户
    问题ayear@DESKTOP-GPCA3B0:~/AdonisJS$nodeace.jsmigration:run[error]Host'DESKTOP-GPCA3B0'isnotallowedtoconnecttothisMySQLserveratPacket.asError(/home/ayear/AdonisJS/node_modules/.pnpm/mysql2@3.9.4/node_modules/mysql2/......
  • Linux下使用docker部署mysql(一)
    1.拉取dockerdockerpullmysql:5.7 2.配置挂载目录sudomkdir-p/docker_data/mysql/datasudomkdir-p/docker_data/mysql/confsudomkdir-p/docker_data/mysql/conf/conf.dsudomkdir-p/docker_data/mysql/conf/mysql.conf.dsudomkdir-p/docker_data/mysql/logs......
  • 通过 aqtinstall 安装 Qt5 的库
    QtMaintenanceTool(QtOnlineInstaller)可能没有Qt5的安装选项了,但是从Qt官网下载的qt-opensource-windows-x86-5.14.2.exe安装器在安装的时候会安装旧的QtCreator。如果你不想要旧的QtCreator并且需要的版本不是Qt5.14.2,安装起来可能不是很方便。有一个命令行工具可......
  • PP-HumanSeg安装、运行、训练、测试
    参考paddleseg官网https://aistudio.baidu.com/projectdetail/2189481?channelType=0&channel=0零、准备工作1.用conda创建虚拟环境#1.查询conda环境下有哪些虚拟环境condainfo--envs#2.创建指定python版本的环境condacreate-nPaddleSeg_py_38python=3.8#3.......
  • Ubuntu18.04安装opensips一次过,实现sip语音视频通话
    安装方式apt命令安装,不建议使用此方式想要在ubuntu18.04(建议使用18.04,不出错)上通过apt命令安装的可以借鉴一下这篇文章,但是这篇文章中博主有错误并未解决,下面是解决方式执行下列命令,使用opensipsdbctl创建数据库的时候会报错opensipsdbctlcreate#错误信息为ERROR:......
  • MySQL入门
    相关概念数据;描述数据特征的符号记录:事物一系列典型的特征表:文件库:文件夹数据库管理软件:mysql,oracle,db2,SQLserver数据库服务器:运行数据库管理软件的计算机统一字符编码统一客户端,服务端,mysqld的字符编码为utf8SQL语句操作文件夹(库)增:createdatabasedb1charset......
  • ubuntu22 安装3090驱动
    1.执行nvidia-smi-a查询显卡资源报错aptinstallnvidia-utils-535-serveraptinstallnvidia-utils-5352.安装驱动nvdia-smi提示未安装驱动预先安装系统:ububtu22.04LTS查看可安装驱动版本:#ubuntu-driversdevicesERROR:root:aplaycommandnotfound==/sys/devices/pci000......
  • 在Windows安装javaSE8
    1.下载安装官网Java1.8_31.zip2.配置环境变量创建.bat文件,写入以下内容后执行。自动配置环境变量@echooff%1mshtavbscript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c%~s0::","","runas",1)(window.close)&&exit......
  • ubuntu 安装 Allure
    试了网上好多种方法都不行,各种AI都问遍了,全都是安装上了但是allure--version的时候没有找到!!!最后这个终于可以了!!! 更新系统软件包列表:bash复制代码运行sudoaptupdate安装Java(JDK8或更高版本):bash复制代码运行sudoaptinstallopenjdk-11-jdk下载Allure命令行工......