当前位置: 首页 > news >正文

Ubuntu20.04安装MySQL5.7与远程连接

一、安装MySQL5.7

1.更换镜像源

sudo cp /etc/apt/sources.list /etc/apt/sources.list.old     #备份原来的文件
sudo vim /etc/apt/sources.list      #修改sources.list文件

配置文件内容如下所示:

# 清华镜像源
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse

2.更新

sudo apt update    # 更新镜像源

3.安装MySQL5.7

sudo apt install -y mysql-server-5.7

(需要输入两次mysql的root用户的密码

软件包设置┌──────────────────────────┤ 正在设定 mysql-server-5.7 ├──────────────────────────┐│ While not mandatory, it is highly recommended that you set a password for the   ││ MySQL administrative "root" user.                                               ││                                                                                 ││ If this field is left blank, the password will not be changed.                  ││                                                                                 ││ New password for the MySQL "root" user:                                         ││                                                                                 ││ *********______________________________________________________________________ ││                                                                                 ││                                     <确定>                                      ││                                                                                 │└─────────────────────────────────────────────────────────────────────────────────┘
软件包设置┌────────┤ 正在设定 mysql-server-5.7 ├────────┐│                                             ││                                             ││ Repeat password for the MySQL "root" user:  ││                                             ││ *********__________________________________ ││                                             ││                   <确定>                    ││                                             │└─────────────────────────────────────────────┘

4、安装完成,查看MySQL的版本

mysql -V    # 查看mysql版本

5、连接MySQL(使用root和刚才设置的root的密码)

➜  ~ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.33-0ubuntu0.16.04.1 (Ubuntu)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> 

二、配置远程连接

1、修改配置文件

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

找到 bind-address 修改值为 0.0.0.0
在这里插入图片描述
重启MySQL

sudo /etc/init.d/mysql restart 

2、为用户授权远程连接服务

使用 root 用户登录 MySQL 数据库

mysql -u root -p

使用 MySQL 命令为 root 用户授权 MySQL 远程连接服务

grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option;

将配置写入 MySQL 授权表中

flush privileges;

然后即可连接远程连接

三、启动、停止服务

#启动
sudo service mysql start
#停止
sudo service mysql stop
http://www.lryc.cn/news/5206.html

相关文章:

  • 【yolov5】首次尝试目标检测利用prompt(完整操作流程)
  • 三大指标继续狂飙!重庆啤酒:不惧强弱分化加剧,深耕高端市场
  • MySQL数据库14——更新和删除数据
  • Java面试——MyBatis篇
  • C++的 new 和 delete
  • MySQL 事务原理
  • 软件测试面试自我介绍/项目介绍居然还有模板?我要是早点发现就好了
  • new RegExp的使用
  • 供应商管理软件如何选型 好用的供应商管理软件推荐
  • Python3遍历文件夹提取关键字及其附近字符
  • 「1」线性代数(期末复习)
  • C++7:STL-模拟实现vector
  • 笑死,面试官又问我SpringBoot自动配置原理
  • 分布式缓存服务DCS-企业版性能更强,稳定性更高
  • HTTP基本原理
  • 【云原生】Kubernetes(k8s)最新版本详细保姆级安装教程
  • JVM - 类加载,连接和初始化
  • [carla]关于odometry坐标中的角度坐标系 以及 到地图的映射问题
  • Python 正则表达式
  • spark03-读取文件数据分区数量个数原理
  • 操作系统(day08)内存
  • 11- 聚类算法 (KMeans/DBSCAN/agg) (机器学习)
  • 日日顺供应链|想要看清供应链发展趋势,先回答这三个问题
  • 5守护进程与线程
  • EZ-Cube简易款下载器烧写使用方法
  • sql server安装并SSMS连接
  • Python_pytorch (二)
  • java手机短信验证,并存入redis中,验证码时效5分钟
  • kubectl命令控制远程k8s集群(Windows系统、Ubuntu系统、Centos系统)
  • 【求解器-COPT】COPT的版本更新中,老版本不能覆盖的问题