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

在以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
在Linux(Ubuntu) 中安装mysql服务器并开启远程访问_第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

十三、远程连接
在Linux(Ubuntu) 中安装mysql服务器并开启远程访问_第2张图片

好了可以愉快的工作了

你可能感兴趣的:(Linux运维部署)