Debian 11安装mysql 5.7.41

  • 1、下载mysql安装包
  • 2、安装文档
  • 2.1、安装依赖包
  • 2.2、安装MySQL包
  • 2.2.1、预设置数据库参数
  • 2.2.2、安装MySQL包
  • 2.3、文件安装位置
  • 3、使用mysql 5.7.41 数据库
  • 3.1、命令行登录MySQL 5.7.41 数据库
  • 3.2、navicat连接mysql 5.7.41 数据库
  • 3.2.1、修改mysql配置文件允许监听所有网卡地址
  • 3.2.2、修改配置允许使用mysql root用户连接数据库
  • 3.3、mysql数据库常用命令<5.7.41版本>
  • 3.3.1、初始化默认数据库


1、下载mysql安装包

访问官方下载页面下载bundle安装包
https://downloads.mysql.com/archives/community/

debian11安装wireshark Debian11安装mysql_mysql

下载文件 然后解压

mkdir -p  /root/package/mysql/mysql-server_5.7.41-1debian10_amd64.deb-bundle
cd /root/package/mysql/
tar -xvf mysql-server_5.7.41-1debian10_amd64.deb-bundle.tar -C mysql-server_5.7.41-1debian10_amd64.deb-bundle/

解压后的文件如图

root@debian:~/package/mysql# tar -xvf mysql-server_5.7.41-1debian10_amd64.deb-bundle.tar -C mysql-server_5.7.41-1debian10_amd64.deb-bundle/
libmysqlclient20_5.7.41-1debian10_amd64.deb
libmysqlclient-dev_5.7.41-1debian10_amd64.deb
libmysqld-dev_5.7.41-1debian10_amd64.deb
mysql-client_5.7.41-1debian10_amd64.deb
mysql-common_5.7.41-1debian10_amd64.deb
mysql-community-client_5.7.41-1debian10_amd64.deb
mysql-community-server_5.7.41-1debian10_amd64.deb
mysql-community-source_5.7.41-1debian10_amd64.deb
mysql-community-test_5.7.41-1debian10_amd64.deb
mysql-server_5.7.41-1debian10_amd64.deb
mysql-testsuite_5.7.41-1debian10_amd64.deb
root@debian:~/package/mysql#

2、安装文档

https://dev.mysql.com/doc/mysql-installation-excerpt/5.7/en/linux-installation-debian.html

2.1、安装依赖包

apt-get install libaio1

2.2、安装MySQL包

2.2.1、预设置数据库参数

cd /root/package/mysql/mysql-server_5.7.41-1debian10_amd64.deb-bundle/
dpkg-preconfigure mysql-community-server_*.deb

此步骤会进行设定mysql的root账户密码
输入root账户密码

debian11安装wireshark Debian11安装mysql_debian11安装wireshark_02

再次输入密码

debian11安装wireshark Debian11安装mysql_数据库_03

按tab键 选中ok 回车

debian11安装wireshark Debian11安装mysql_数据库_04

包文件如图所示

root@debian:~/package/mysql/mysql-server_5.7.41-1debian10_amd64.deb-bundle# ls -lh
total 159M
-rw-r--r-- 1 7155 31415 1.8M Dec  7 12:50 libmysqlclient20_5.7.41-1debian10_amd64.deb
-rw-r--r-- 1 7155 31415 2.3M Dec  7 12:51 libmysqlclient-dev_5.7.41-1debian10_amd64.deb
-rw-r--r-- 1 7155 31415  20M Dec  7 12:50 libmysqld-dev_5.7.41-1debian10_amd64.deb
-rw-r--r-- 1 7155 31415  69K Dec  7 12:50 mysql-client_5.7.41-1debian10_amd64.deb
-rw-r--r-- 1 7155 31415  72K Dec  7 12:50 mysql-common_5.7.41-1debian10_amd64.deb
-rw-r--r-- 1 7155 31415  15M Dec  7 12:50 mysql-community-client_5.7.41-1debian10_amd64.deb
-rw-r--r-- 1 7155 31415  38M Dec  7 12:50 mysql-community-server_5.7.41-1debian10_amd64.deb
-rw-r--r-- 1 7155 31415  52M Dec  7 12:50 mysql-community-source_5.7.41-1debian10_amd64.deb
-rw-r--r-- 1 7155 31415  32M Dec  7 12:50 mysql-community-test_5.7.41-1debian10_amd64.deb
-rw-r--r-- 1 7155 31415  69K Dec  7 12:51 mysql-server_5.7.41-1debian10_amd64.deb
-rw-r--r-- 1 7155 31415  69K Dec  7 12:50 mysql-testsuite_5.7.41-1debian10_amd64.deb
root@debian:~/package/mysql/mysql-server_5.7.41-1debian10_amd64.deb-bundle#

2.2.2、安装MySQL包

安装MySQL包
本次安装失败 是因为依赖关系缺少的依赖包未安装导致导致安装失败

root@debian:~/package/mysql/mysql-server_5.7.41-1debian10_amd64.deb-bundle# dpkg -i mysql-{common,community-client,client,community-server,server}_*.deb
Selecting previously unselected package mysql-common.
(Reading database ... 141511 files and directories currently installed.)
Preparing to unpack mysql-common_5.7.41-1debian10_amd64.deb ...
Unpacking mysql-common (5.7.41-1debian10) ...
Selecting previously unselected package mysql-community-client.
Preparing to unpack mysql-community-client_5.7.41-1debian10_amd64.deb ...
Unpacking mysql-community-client (5.7.41-1debian10) ...
Selecting previously unselected package mysql-client.
Preparing to unpack mysql-client_5.7.41-1debian10_amd64.deb ...
Unpacking mysql-client (5.7.41-1debian10) ...
Selecting previously unselected package mysql-community-server.
Preparing to unpack mysql-community-server_5.7.41-1debian10_amd64.deb ...
Unpacking mysql-community-server (5.7.41-1debian10) ...
Selecting previously unselected package mysql-server.
Preparing to unpack mysql-server_5.7.41-1debian10_amd64.deb ...
Unpacking mysql-server (5.7.41-1debian10) ...
Setting up mysql-common (5.7.41-1debian10) ...
update-alternatives: using /etc/mysql/my.cnf.fallback to provide /etc/mysql/my.cnf (my.cnf) in auto mode
Setting up mysql-community-client (5.7.41-1debian10) ...
Setting up mysql-client (5.7.41-1debian10) ...
dpkg: dependency problems prevent configuration of mysql-community-server:
 mysql-community-server depends on libmecab2; however:
  Package libmecab2 is not installed.

dpkg: error processing package mysql-community-server (--install):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of mysql-server:
 mysql-server depends on mysql-community-server (= 5.7.41-1debian10); however:
  Package mysql-community-server is not configured yet.

dpkg: error processing package mysql-server (--install):
 dependency problems - leaving unconfigured
Processing triggers for man-db (2.9.4-2) ...
Errors were encountered while processing:
 mysql-community-server
 mysql-server
root@debian:~/package/mysql/mysql-server_5.7.41-1debian10_amd64.deb-bundle#

apt-get -f install 修复上述问题

apt-get -f install

安装过程会自动创建MySQL的systemd服务

root@debian:~/package/mysql/mysql-server_5.7.41-1debian10_amd64.deb-bundle# apt-get -f install
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Correcting dependencies... Done
The following package was automatically installed and is no longer required:
  libopengl0
Use 'apt autoremove' to remove it.
The following additional packages will be installed:
  libmecab2
The following NEW packages will be installed:
  libmecab2
0 upgraded, 1 newly installed, 0 to remove and 1 not upgraded.
2 not fully installed or removed.
Need to get 221 kB of archives.
After this operation, 1,817 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 https://mirrors.tuna.tsinghua.edu.cn/debian bullseye/main amd64 libmecab2 amd64 0.996-14+b4 [221 kB]
Fetched 221 kB in 0s (1,823 kB/s)
Selecting previously unselected package libmecab2:amd64.
(Reading database ... 141756 files and directories currently installed.)
Preparing to unpack .../libmecab2_0.996-14+b4_amd64.deb ...
Unpacking libmecab2:amd64 (0.996-14+b4) ...
Setting up libmecab2:amd64 (0.996-14+b4) ...
Setting up mysql-community-server (5.7.41-1debian10) ...
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.
Setting up mysql-server (5.7.41-1debian10) ...
Processing triggers for libc-bin (2.31-13+deb11u6) ...
root@debian:~/package/mysql/mysql-server_5.7.41-1debian10_amd64.deb-bundle#

此次安装是mysql数据库基本安装方式,只安装了这些包。没有安装开发包。

debian11安装wireshark Debian11安装mysql_mysql_05

至此安装MySQL 5.7.41成功,查看MySQL服务状态,在安装时已经设置了开机自启动,不需要可以禁用。

systemctl status mysql.service
root@debian:~/package/mysql# systemctl status mysql.service 
● mysql.service - MySQL Community Server
     Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
     Active: active (running) since Thu 2023-05-11 04:48:39 EDT; 51min ago
    Process: 2623 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
    Process: 2679 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid (code=exited, status=0/SUCCESS)
   Main PID: 2685 (mysqld)
      Tasks: 27 (limit: 9433)
     Memory: 190.5M
        CPU: 1.790s
     CGroup: /system.slice/mysql.service
             └─2685 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

May 11 04:48:38 debian systemd[1]: Starting MySQL Community Server...
May 11 04:48:39 debian systemd[1]: Started MySQL Community Server.
root@debian:~/package/mysql#

禁用MySQL开机自启动

systemctl disable mysql.service

2.3、文件安装位置

Here are where the files are installed on the system:

  • All configuration files (like my.cnf) are under /etc/mysql
  • All binaries, libraries, headers, etc., are under /usr/bin and /usr/sbin
  • The data directory is /var/lib/mysql
root@debian:~/package/mysql# ls -lh /etc/mysql
total 16K
drwxr-xr-x 2 root root 4.0K May 11 04:47 conf.d
lrwxrwxrwx 1 root root   24 May 11 04:48 my.cnf -> /etc/alternatives/my.cnf
-rw-r--r-- 1 root root 1.5K Dec  7 13:25 my.cnf.fallback
-rw-r--r-- 1 root root 1.2K Dec  7 13:25 mysql.cnf
drwxr-xr-x 2 root root 4.0K May 11 04:48 mysql.conf.d
root@debian:~/package/mysql#
root@debian:~/package/mysql# ls -lh /usr/bin/|grep "mysql*"
-rwxr-xr-x 1 root root    6.9M Dec  7 13:25 mysql
-rwxr-xr-x 1 root root    6.5M Dec  7 13:25 mysqladmin
-rwxr-xr-x 1 root root    6.8M Dec  7 13:25 mysqlbinlog
-rwxr-xr-x 1 root root    6.5M Dec  7 13:25 mysqlcheck
-rwxr-xr-x 1 root root    5.8M Dec  7 13:25 mysql_config_editor
-rwxr-xr-x 1 root root     27K Dec  7 13:25 mysqld_multi
-rwxr-xr-x 1 root root     28K Dec  7 13:25 mysqld_safe
-rwxr-xr-x 1 root root    6.6M Dec  7 13:25 mysqldump
-rwxr-xr-x 1 root root    7.7K Dec  7 13:25 mysqldumpslow
-rwxr-xr-x 1 root root     27M Dec  7 13:25 mysql_embedded
-rwxr-xr-x 1 root root    6.5M Dec  7 13:25 mysqlimport
-rwxr-xr-x 1 root root    7.4M Dec  7 13:25 mysql_install_db
-rwxr-xr-x 1 root root    5.8M Dec  7 13:25 mysql_plugin
-rwxr-xr-x 1 root root    7.2M Dec  7 13:25 mysqlpump
-rwxr-xr-x 1 root root    6.5M Dec  7 13:25 mysql_secure_installation
-rwxr-xr-x 1 root root    6.5M Dec  7 13:25 mysqlshow
-rwxr-xr-x 1 root root    6.5M Dec  7 13:25 mysqlslap
-rwxr-xr-x 1 root root    5.8M Dec  7 13:25 mysql_ssl_rsa_setup
-rwxr-xr-x 1 root root    3.5M Dec  7 13:25 mysql_tzinfo_to_sql
-rwxr-xr-x 1 root root    7.2M Dec  7 13:25 mysql_upgrade
root@debian:~/package/mysql# ls -lh /usr/sbin/|grep "mysql*"
-rwxr-xr-x 1 root root    29M Dec  7 13:25 mysqld
-rwxr-xr-x 1 root root    46M Dec  7 13:25 mysqld-debug
root@debian:~/package/mysql#
root@debian:~/package/mysql# ls -lh  /var/lib/mysql
total 121M
-rw-r----- 1 mysql mysql   56 May 11 04:48 auto.cnf
-rw------- 1 mysql mysql 1.7K May 11 04:48 ca-key.pem
-rw-r--r-- 1 mysql mysql 1.1K May 11 04:48 ca.pem
-rw-r--r-- 1 mysql mysql 1.1K May 11 04:48 client-cert.pem
-rw------- 1 mysql mysql 1.7K May 11 04:48 client-key.pem
-rw-r----- 1 mysql mysql  350 May 11 04:48 ib_buffer_pool
-rw-r----- 1 mysql mysql  12M May 11 04:48 ibdata1
-rw-r----- 1 mysql mysql  48M May 11 04:48 ib_logfile0
-rw-r----- 1 mysql mysql  48M May 11 04:48 ib_logfile1
-rw-r----- 1 mysql mysql  12M May 11 04:48 ibtmp1
drwxr-x--- 2 mysql mysql 4.0K May 11 04:48 mysql
drwxr-x--- 2 mysql mysql 4.0K May 11 04:48 performance_schema
-rw------- 1 mysql mysql 1.7K May 11 04:48 private_key.pem
-rw-r--r-- 1 mysql mysql  452 May 11 04:48 public_key.pem
-rw-r--r-- 1 mysql mysql 1.1K May 11 04:48 server-cert.pem
-rw------- 1 mysql mysql 1.7K May 11 04:48 server-key.pem
drwxr-x--- 2 mysql mysql  12K May 11 04:48 sys
root@debian:~/package/mysql#

3、使用mysql 5.7.41 数据库

3.1、命令行登录MySQL 5.7.41 数据库

登录数据库root账户 密码是安装MySQL时设置的root账户密码

mysql -uroot -p
root@debian:~/package/mysql# 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.41 MySQL Community Server (GPL)

Copyright (c) 2000, 2023, 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>

查看默认所有数据库

show databases;
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

mysql>

创建数据库

create database test;
mysql> create database test;
Query OK, 1 row affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| test               |
+--------------------+
5 rows in set (0.01 sec)

mysql>

3.2、navicat连接mysql 5.7.41 数据库

新建连接 选择mysql

debian11安装wireshark Debian11安装mysql_mysql_06

点击 连接测试

debian11安装wireshark Debian11安装mysql_debian_07

报错

debian11安装wireshark Debian11安装mysql_mysql_08

需修改以下2点配置解决

3.2.1、修改mysql配置文件允许监听所有网卡地址

原因是默认安装完mysql后 只允许在mysql服务器本机发起数据库连接

ss -anlp|grep 3306

debian11安装wireshark Debian11安装mysql_debian_09

本机可以通3306

debian11安装wireshark Debian11安装mysql_数据库_10

外部机器不可以通3306

debian11安装wireshark Debian11安装mysql_debian_11

修改MySQL配置文件 使得MySQL监听在所有网卡上,也就是允许所有IP地址发起数据库连接

cp /etc/mysql/mysql.conf.d/mysqld.cnf /etc/mysql/mysql.conf.d/mysqld.cnf.bak
/etc/mysql/mysql.conf.d/mysqld.cnf

编辑MySQL配置文件

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

修改bind-address = 127.0.0.1

debian11安装wireshark Debian11安装mysql_debian11安装wireshark_12

修改为:bind-address = 0.0.0.0

debian11安装wireshark Debian11安装mysql_mysql_13

重启MySQL服务

systemctl restart mysql.service

再次查看监听配置

ss -anlp|grep 3306

debian11安装wireshark Debian11安装mysql_debian_14

navicat测试连接数据库 仍然报错

debian11安装wireshark Debian11安装mysql_mysql_15

Windows机器telnet 数据库IP 3306 测试

debian11安装wireshark Debian11安装mysql_debian_16

3.2.2、修改配置允许使用mysql root用户连接数据库

修改配置允许使用mysql root用户连接数据库
登录MySQL数据库

mysql -uroot -p

修改修改配置使得可以允许外部所有IP地址发起数据库连接,用户是root 密码是password(安装时设置的MySQL的root账户密码) ,拥有所有库和表的访问权限。

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

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

mysql>

navicat再次测试连接 连接成功

debian11安装wireshark Debian11安装mysql_debian_17

debian11安装wireshark Debian11安装mysql_debian_18

新建查询

debian11安装wireshark Debian11安装mysql_debian11安装wireshark_19

debian11安装wireshark Debian11安装mysql_debian_20

debian11安装wireshark Debian11安装mysql_MySQL_21

3.3、mysql数据库常用命令<5.7.41版本>

3.3.1、初始化默认数据库

初始化默认数据库

mysqld --initialize --console

debian11安装wireshark Debian11安装mysql_数据库_22


debian11安装wireshark Debian11安装mysql_数据库_23

mysqld命令帮助查看:

mysqld --verbose --help|less

debian11安装wireshark Debian11安装mysql_mysql_24