文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

Ubuntu安装mysql5.7(适用于大多数ubuntu版本)

2023-09-04 12:59

关注

前言:网上mysql的安装方式参差不齐,有的装了缺少配置文件,有的装了少库少表 所以现在出一个完整的mysql安装方案

目前安装方式无外乎有下面三种:

  1. 装完没有密码,需要自己进去设置密码
  2. 装完有默认密码,需要查看并进去在自己修改
  3. 安装的时候输入密码,安装完成后直接使用

本文使用的正是第三种

1、mysql的下载

mysql官网下载地址:https://dev.mysql.com/downloads/mysql/

进入后 点击红圈的链接

在这里插入图片描述

就会进入到5.7的下载界面了 可以根据需要下载对应系统所需要的包

在这里插入图片描述

这里我们下载对应ubuntu的tar包 并且将其上传到ubuntu内

在这里插入图片描述

解压

root@wdr:/opt# mkdir /opt/mysqlroot@wdr:~# tar -xvf mysql-server_5.7.42-1ubuntu18.04_amd64.deb-bundle.tar -C /opt/mysql/libmysqlclient20_5.7.42-1ubuntu18.04_amd64.deblibmysqlclient-dev_5.7.42-1ubuntu18.04_amd64.deblibmysqld-dev_5.7.42-1ubuntu18.04_amd64.debmysql-client_5.7.42-1ubuntu18.04_amd64.debmysql-common_5.7.42-1ubuntu18.04_amd64.debmysql-community-client_5.7.42-1ubuntu18.04_amd64.debmysql-community-server_5.7.42-1ubuntu18.04_amd64.debmysql-community-source_5.7.42-1ubuntu18.04_amd64.debmysql-community-test_5.7.42-1ubuntu18.04_amd64.debmysql-server_5.7.42-1ubuntu18.04_amd64.debmysql-testsuite_5.7.42-1ubuntu18.04_amd64.debroot@wdr:~# 

查看

root@wdr:~# cd /opt/mysql/root@wdr:/opt/mysql# lslibmysqlclient20_5.7.42-1ubuntu18.04_amd64.deb        mysql-community-server_5.7.42-1ubuntu18.04_amd64.deblibmysqlclient-dev_5.7.42-1ubuntu18.04_amd64.deb      mysql-community-source_5.7.42-1ubuntu18.04_amd64.deblibmysqld-dev_5.7.42-1ubuntu18.04_amd64.deb           mysql-community-test_5.7.42-1ubuntu18.04_amd64.debmysql-client_5.7.42-1ubuntu18.04_amd64.deb            mysql-server_5.7.42-1ubuntu18.04_amd64.debmysql-common_5.7.42-1ubuntu18.04_amd64.deb            mysql-testsuite_5.7.42-1ubuntu18.04_amd64.debmysql-community-client_5.7.42-1ubuntu18.04_amd64.debroot@wdr:/opt/mysql# 

使用dpkg -i命令顺序安装 安装最后mysql-community-server这个包的时候可能会报错 但是不要惊慌

dpkg -i mysql-common_5.7.42-1ubuntu18.04_amd64.deb dpkg -i libmysqlclient20_5.7.42-1ubuntu18.04_amd64.deb dpkg -i libmysqlclient-dev_5.7.42-1ubuntu18.04_amd64.deb dpkg -i libmysqld-dev_5.7.42-1ubuntu18.04_amd64.deb dpkg -i mysql-community-server_5.7.42-1ubuntu18.04_amd64.deb

在安装mysql server这个包的时候 会报依赖错误 告诉我们缺少mysql-client 而且还少libmecab libmecab我们暂时先不管 后面有命令统一解决

root@wdr:/opt/mysql# dpkg -i mysql-community-server_5.7.42-1ubuntu18.04_amd64.deb Selecting previously unselected package mysql-community-server.(Reading database ... 74128 files and directories currently installed.)Preparing to unpack mysql-community-server_5.7.42-1ubuntu18.04_amd64.deb ...Unpacking mysql-community-server (5.7.42-1ubuntu18.04) ...dpkg: dependency problems prevent configuration of mysql-community-server:mysql-community-server depends on mysql-client (= 5.7.42-1ubuntu18.04); however:Package mysql-client is not installed.mysql-community-server depends on libmecab2; however:Package libmecab2 is not installed.dpkg: error processing package mysql-community-server (--install):dependency problems - leaving unconfiguredProcessing triggers for man-db (2.10.2-1) ...Errors were encountered while processing:mysql-community-server

我们先安装mysql-client 然后此时你会发现 又提示缺少mysql-community-client这个依赖包 继续装

root@wdr:/opt/mysql# dpkg -i mysql-client_5.7.42-1ubuntu18.04_amd64.deb Selecting previously unselected package mysql-client.(Reading database ... 74290 files and directories currently installed.)Preparing to unpack mysql-client_5.7.42-1ubuntu18.04_amd64.deb ...Unpacking mysql-client (5.7.42-1ubuntu18.04) ...dpkg: dependency problems prevent configuration of mysql-client:mysql-client depends on mysql-community-client (= 5.7.42-1ubuntu18.04); however:Package mysql-community-client is not installed.dpkg: error processing package mysql-client (--install):dependency problems - leaving unconfiguredErrors were encountered while processing:mysql-clientroot@wdr:/opt/mysql# 

现在他只告诉你缺少libmecab这个包了 在不同的ubuntu版本下 缺少的版本并不相同 比如这里缺少libtinfo5 然而在有的环境下缺libtinfo1 libtinfo2 等等

root@wdr:/opt/mysql# dpkg -i mysql-community-client_5.7.42-1ubuntu18.04_amd64.deb Selecting previously unselected package mysql-community-client.(Reading database ... 74296 files and directories currently installed.)Preparing to unpack mysql-community-client_5.7.42-1ubuntu18.04_amd64.deb ...Unpacking mysql-community-client (5.7.42-1ubuntu18.04) ...dpkg: dependency problems prevent configuration of mysql-community-client:mysql-community-client depends on libtinfo5 (>= 6); however:Package libtinfo5 is not installed.dpkg: error processing package mysql-community-client (--install):dependency problems - leaving unconfiguredProcessing triggers for man-db (2.10.2-1) ...Errors were encountered while processing:mysql-community-client 

下面我们只需要使用 apt --fix-broken install 这条命令来自动解决当前所出现的依赖 就可以完美解决问题了 选择Y同意

root@wdr:/opt/mysql# apt --fix-broken installReading package lists... DoneBuilding dependency tree... DoneReading state information... DoneCorrecting dependencies... DoneThe following additional packages will be installed:libmecab2 libtinfo5The following NEW packages will be installed:libmecab2 libtinfo50 upgraded, 2 newly installed, 0 to remove and 50 not upgraded.3 not fully installed or removed.Need to get 298 kB of archives.After this operation, 1,432 kB of additional disk space will be used.Do you want to continue? [Y/n] 

同意继续后 安装一会就会提示你输入mysql的root密码了

在这里插入图片描述

我们输入完两次密码后 mysql的安装也就完成了

root@wdr:/opt/mysql# mysql -u root -p123456mysql: [Warning] Using a password on the command line interface can be insecure.Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 3Server version: 5.7.42 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> 

当然 mysql的安装是完成了 但是此时它并不能为我们的程序提供服务(使用连接工具现在是连接不上的) 因为还需要配置远程连接 使我们可以远程登录才可以

首先 进入mysql库 查看user表 会发现我们的root用户是localhost

mysql> use mysql;Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -ADatabase changedmysql> mysql> select User,Host from user;+---------------+-----------+| User          | Host      |+---------------+-----------+| mysql.session | localhost || mysql.sys     | localhost || root          | localhost |+---------------+-----------+3 rows in set (0.00 sec)mysql> 

将其修改 并使其立即生效

mysql> update user set host = '%' where user = 'root'; Query OK, 1 row affected (0.00 sec)Rows matched: 1  Changed: 1  Warnings: 0mysql> select User,Host from user;+---------------+-----------+| User          | Host      |+---------------+-----------+| root          | %         || mysql.session | localhost || mysql.sys     | localhost |+---------------+-----------+3 rows in set (0.00 sec)mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)mysql> 

此时到这里并未结束 我们还需要修改mysql的配置文件 我们需要修改位于/etc/mysql/mysql.conf.d/mysqld.cnf 的配置文件

root@wdr:/opt/mysql# vim /etc/mysql/mysql.conf.d/mysqld.cnf 

将其bind-address改为0.0.0.0

在这里插入图片描述

保存退出 重启mysql服务

root@wdr:/opt/mysql# systemctl restart mysqlroot@wdr:/opt/mysql# 

重启成功 现在我们可以使用连接工具连接了

保存退出 重启mysql服务

root@wdr:/opt/mysql# systemctl restart mysqlroot@wdr:/opt/mysql# 

重启成功 现在我们可以使用连接工具连接了在这里插入图片描述

至此 mysql的安装已全部完成 如果有部署在云服务器上的经过上列操作无法访问的话 记得查看后台防火墙端口是否开启

来源地址:https://blog.csdn.net/qq_41265137/article/details/130644812

阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     813人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     354人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     318人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     435人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     224人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-数据库
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯