Debian 11安装mysql 5.7.41
Debian 11安装mysql 5.7.41
1、下载mysql安装包
访问官方下载页面下载bundle安装包
https://downloads.mysql.com/archives/community/
下载文件 然后解压
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.deblibmysqlclient-dev_5.7.41-1debian10_amd64.deblibmysqld-dev_5.7.41-1debian10_amd64.debmysql-client_5.7.41-1debian10_amd64.debmysql-common_5.7.41-1debian10_amd64.debmysql-community-client_5.7.41-1debian10_amd64.debmysql-community-server_5.7.41-1debian10_amd64.debmysql-community-source_5.7.41-1debian10_amd64.debmysql-community-test_5.7.41-1debian10_amd64.debmysql-server_5.7.41-1debian10_amd64.debmysql-testsuite_5.7.41-1debian10_amd64.debroot@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账户密码
再次输入密码
按tab键 选中ok 回车
包文件如图所示
root@debian:~/package/mysql/mysql-server_5.7.41-1debian10_amd64.deb-bundle# ls -lhtotal 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.debroot@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}_*.debSelecting 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 modeSetting 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 unconfigureddpkg: 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 unconfiguredProcessing triggers for man-db (2.9.4-2) ...Errors were encountered while processing: mysql-community-server mysql-serverroot@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 installReading package lists... DoneBuilding dependency tree... DoneReading state information... DoneCorrecting dependencies... DoneThe following package was automatically installed and is no longer required: libopengl0Use 'apt autoremove' to remove it.The following additional packages will be installed: libmecab2The following NEW packages will be installed: libmecab20 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] yGet: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 modeCreated 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数据库基本安装方式,只安装了这些包。没有安装开发包。
至此安装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.pidMay 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/mysqltotal 16Kdrwxr-xr-x 2 root root 4.0K May 11 04:47 conf.dlrwxrwxrwx 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.cnfdrwxr-xr-x 2 root root 4.0K May 11 04:48 mysql.conf.droot@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_upgraderoot@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-debugroot@debian:~/package/mysql#
root@debian:~/package/mysql# ls -lh /var/lib/mysqltotal 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 ibtmp1drwxr-x--- 2 mysql mysql 4.0K May 11 04:48 mysqldrwxr-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.pemdrwxr-x--- 2 mysql mysql 12K May 11 04:48 sysroot@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 -pEnter password: Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 2Server 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 itsaffiliates. Other names may be trademarks of their respectiveowners.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
点击 连接测试
报错
需修改以下2点配置解决
3.2.1、修改mysql配置文件允许监听所有网卡地址
原因是默认安装完mysql后 只允许在mysql服务器本机发起数据库连接
ss -anlp|grep 3306
本机可以通3306
外部机器不可以通3306
修改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
修改为:bind-address = 0.0.0.0
重启MySQL服务
systemctl restart mysql.service
再次查看监听配置
ss -anlp|grep 3306
navicat测试连接数据库 仍然报错
Windows机器telnet 数据库IP 3306 测试
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再次测试连接 连接成功
新建查询
3.3、mysql数据库常用命令<5.7.41版本>
3.3.1、初始化默认数据库
初始化默认数据库
mysqld --initialize --console
mysqld命令帮助查看:
mysqld --verbose --help|less
来源地址:https://blog.csdn.net/OceanWaves1993/article/details/130622988
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341