在Linux(Ubuntu) 中安装mysql服务器并开启远程访问

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介: 在以linux为内核的有centos和ubuntu,推荐大家使用ubuntu,因为使用的人数多,出现了问题方便及时解决问题一、创建一个云主机$ ssh root@39.

在以linux为内核的有centos和ubuntu,推荐大家使用ubuntu,因为使用的人数多,出现了问题方便及时解决问题

一、创建一个云主机

$ ssh root@39.107.227.105
The authenticity of host '39.107.227.105 (39.107.227.105)' can't be established.
ECDSA key fingerprint is SHA256:XHVNl/fJcKil0FDguV52zXKbEt/qmju6W3mctR2JLVY.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '39.107.227.105' (ECDSA) to the list of known hosts.
root@39.107.227.105's password: 
Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.4.0-105-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

Welcome to Alibaba Cloud Elastic Compute Service !

二、安装mysql服务器版本和客户端版本

sudo apt-get install mysql-server
sudo apt install mysql-client

三、会报一个错

root@iZ2zeht3zvxbq5ycy698pwZ:~# apt-get install mysql-server
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package mysql-server
root@iZ2zeht3zvxbq5ycy698pwZ:~# 

四、升级一下安装源

root@iZ2zeht3zvxbq5ycy698pwZ:~# apt-get update
Get:1 http://mirrors.cloud.aliyuncs.com/ubuntu xenial InRelease [247 kB]
Get:2 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-updates InRelease [102 kB]
Get:3 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-security InRelease [102 kB]
Get:4 http://mirrors.cloud.aliyuncs.com/ubuntu xenial/main Sources [868 kB]
Get:5 http://mirrors.cloud.aliyuncs.com/ubuntu xenial/universe Sources [7728 kB]
Get:6 http://mirrors.cloud.aliyuncs.com/ubuntu xenial/main amd64 Packages [1201 kB]
Get:7 http://mirrors.cloud.aliyuncs.com/ubuntu xenial/main i386 Packages [1196 kB]
Get:8 http://mirrors.cloud.aliyuncs.com/ubuntu xenial/main Translation-en [568 kB]
Get:9 http://mirrors.cloud.aliyuncs.com/ubuntu xenial/universe amd64 Packages [7532 kB]

五、在执行一下安装操作

root@iZ2zeht3zvxbq5ycy698pwZ:~# apt-get install mysql-server
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  libcgi-fast-perl libcgi-pm-perl libencode-locale-perl libevent-core-2.0-5
  libfcgi-perl libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl
  libhttp-date-perl libhttp-message-perl libio-html-perl
  liblwp-mediatypes-perl liburi-perl mysql-client-5.7 mysql-client-core-5.7
  mysql-common mysql-server-5.7 mysql-server-core-5.7
Suggested packages:
  libdata-dump-perl libipc-sharedcache-perl libwww-perl tinyca

六、在安装的过程中会让你给root用户设置密码

七、看一下是否安装成功,如下图就安装成功了

root@iZ2zeht3zvxbq5ycy698pwZ:~# sudo netstat -tap | grep mysql
sudo: unable to resolve host iZ2zeht3zvxbq5ycy698pwZ
tcp        0      0 localhost:mysql         *:*                     LISTEN      3532/mysqld     
root@iZ2zeht3zvxbq5ycy698pwZ:~# 

八、编辑mysql的配置文件,位于/etc/mysql/mysql.conf.d下的mysqld.cnf

root@iZ2zeht3zvxbq5ycy698pwZ:/etc/mysql# vi mysql.cnf
root@iZ2zeht3zvxbq5ycy698pwZ:/etc/mysql# cd mysql.conf.d
root@iZ2zeht3zvxbq5ycy698pwZ:/etc/mysql/mysql.conf.d# ls
mysqld.cnf  mysqld_safe_syslog.cnf
root@iZ2zeht3zvxbq5ycy698pwZ:/etc/mysql/mysql.conf.d# pwd
/etc/mysql/mysql.conf.d
root@iZ2zeht3zvxbq5ycy698pwZ:/etc/mysql/mysql.conf.d#

九、注释掉bind-address = 127.0.0.1
这里写图片描述

十、 进入mysql,进行授权命令

grant all on *.* to root@'%' identified by '你的密码' with grant option;
mysql> grant all on *.* to root@'%' identified by 'hello123456' with grant option;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> 

十一、刷新一下权限

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

mysql> 

十二、退出mysql,重启mysql服务

root@iZ2zeht3zvxbq5ycy698pwZ:~# service mysql restart

十三、远程连接
这里写图片描述

好了可以愉快的工作了

相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
3天前
|
Linux 开发工具 C语言
Linux 安装 gcc 编译运行 C程序
Linux 安装 gcc 编译运行 C程序
20 0
|
3天前
|
Ubuntu Linux Python
Linux(15)Ubuntu安装ninja构建工具
Linux(15)Ubuntu安装ninja构建工具
13 0
|
5天前
|
NoSQL Linux 测试技术
Redis的安装(Linux版)
Redis的安装(Linux版)
146 1
|
15天前
|
缓存 Linux 测试技术
安装【银河麒麟V10】linux系统--并挂载镜像
安装【银河麒麟V10】linux系统--并挂载镜像
81 0
|
15天前
|
Linux C语言
linux yum安装ffmpeg 图文详解
linux yum安装ffmpeg 图文详解
36 0
|
16天前
|
NoSQL Linux Redis
linux 下和win下安装redis 并添加开机自启 图文详解
linux 下和win下安装redis 并添加开机自启 图文详解
17 0
|
16天前
|
Linux
linux yum 安装rar和unrar
linux yum 安装rar和unrar
52 0
|
1天前
|
Ubuntu Linux
Linux(Ubuntu)系统临时IP以及静态IP配置(关闭、启动网卡等操作)
请注意,以上步骤是在临时基础上进行配置的。如果要永久保存静态IP地址,通常还需要修改 `/etc/network/interfaces`文件,以便在系统重启后保持配置。同时,确保备份相关配置文件以防止出现问题。
6 1
|
1天前
|
监控 安全 Linux
Linux系统之安装ServerBee服务器监控工具
【4月更文挑战第22天】Linux系统之安装ServerBee服务器监控工具
39 2
|
2天前
|
Ubuntu Linux 数据安全/隐私保护
Linux(24) 如何在Ubuntu中操作rootfs.img文件
Linux(24) 如何在Ubuntu中操作rootfs.img文件
3 0