[mysql][ubuntu]ubuntu18云服务器安装mysql5.7
现在服务器普遍都是云服务器了,必然需要经常在服务器上安装软件,而MYSQL也是常用的软件之一,虽然现在很多都在使用docker ,还是记录一下。### 查看系统信息
检查是否有MYSQL
!(data/attachment/forum/202206/30/135334mzculrdv1addlihs.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")
确认系统信息
!(data/attachment/forum/202206/30/135353rpyl625l9ht5gz2t.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")
### 下载
下载文件
```https://dev.mysql.com/downloads/mysql/5.7.html#downloads```
!(data/attachment/forum/202206/30/135438ujzjalxjizzxelmj.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")
!(data/attachment/forum/202206/30/135444qx6jlktskklfk1zx.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")
下载以后可以MD5 校验一下,防止有意外,不校验一般情况下也没啥
### 上传、解压缩
使用自己常用的ftp工具上传到指定位置,然后解压缩即可
!(data/attachment/forum/202206/30/135528hzhk73h7h3hzk67z.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")
!(data/attachment/forum/202206/30/135553kviesq0smq3neti2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")
`本文作者:程序员潇然 疯狂的字节X https://crazybytex.com/`
检查是否安装了libaio1
!(data/attachment/forum/202206/30/135846cysspouwrzxm5zmx.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")
如果没有安装,进行安装
```apt-get install libaio1```
### 开始安装
进入刚才解压好的路径执行:
```dpkg-preconfigure mysql-community-server_*.deb```
!(data/attachment/forum/202206/30/140114ly7icuspyszuppwn.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")
会弹出来界面,需要输入两次密码,输入两次密码即可,这个就是设置密码
继续安装,输入
```dpkg -i mysql-{common,community-client,client,community-server,server}_*.deb```
!(data/attachment/forum/202206/30/140139mslxuoavzuuuovuo.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")
发现报错了~
!(data/attachment/forum/202206/30/140155nt4i44ov8iboiiat.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")
关键错误信息为:
!(data/attachment/forum/202206/30/140207ezk11xfohb1i558i.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")
那么继续安装缺少的组件
```apt-get install libmecab2```
!(data/attachment/forum/202206/30/140226rb12ao40a21apwtl.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")
再次重新执行刚才的命令,完成安装。
ps:对于这个下次可以先确认下是否存在,不存在就可以提前安装了,就不会报错了
!(data/attachment/forum/202206/30/140241efhfkxtp5xlz4dv5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")
### 文件位置
* 所有配置文件( 如my.cnf )都在 /etc/mysql 目录下
* 所有二进制文件、支持库、头文件等都存放在 /usr/bin 和 /usr/sbin 目录下
* 数据文件存放在 /var/lib/mysql 目录下
!(data/attachment/forum/202206/30/140455m1aafhb9gmnahhgh.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")
### 查看版本信息
!(data/attachment/forum/202206/30/140410oyjjgdwl0j7yz0az.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")
### 配置文件调整
修改配置文件,设置一下字符集
!(data/attachment/forum/202206/30/140520khvnbbb3655kah5v.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")
修改配置后需要重启MYSQL
```
service mysql restart
```
!(data/attachment/forum/202206/30/140539hdr8pmiddqfi86fm.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")
重新登陆可以查看字符集的情况
!(data/attachment/forum/202206/30/140600bfuyn13bman2wzwm.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")
### 连接
至此,说明一切安装OK,但是正常情况下是**无法被远程连接**的,涉及端口、配置等一些东西,可以就此检查下
!(data/attachment/forum/202206/30/140637y8u3gtguyvyrzi7u.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")
防火墙是关闭的
```netstat -an|grep 3306```
!(data/attachment/forum/202206/30/140655n76h6zjqn7zwnqdk.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")
默认情况下,它开放的是127.0.0.1:3306而不是0.0.0.0:3306,这是配置文件中设置的
重新修改配置文件
!(data/attachment/forum/202206/30/140719ufkzzhqfk0h0cccf.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")
然后进行重启,启动之后进行连接,发现还是连不上
!(data/attachment/forum/202206/30/140802moiy2rzi356b5u5q.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")
mysql库中user表的root用户的host没有指定为%,而是默认的localhost,在mysql客户端执行如下操作即可
```
# 1、切换到mysql库
use mysql;
#2、查看root用户的host是不是 %,如果是localhost继续下面操作
select user,authentication_string,host from user where user = 'root';
# %为任意主机,就是任意主机可以通过用户名root + 密码 进行连接,你也可以指定只允许某IP的主机进行连接
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '密码';
# 如果之前没有密码,最好再设置下密码,发现上面语句不会产生密码,否则后面连接可能会提示无权限需要更新客户端
alter user 'root'@'%' identified with mysql_native_password by '密码';
# mysql重新加载用户权限
flush privileges;
```
!(data/attachment/forum/202206/16/141330jha7st9soow8772i.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "common_log.png")
`转载务必注明出处:程序员潇然,疯狂的字节X,https://www.crazybytex.com/thread-28-1-1.html `
页:
[1]