腾讯云安装mysql并配置远程连接

清疚 2022-05-30 09:41 368阅读 0赞

环境 :
操作系统:centos 7.2
mysql版本: mysql 5.7
MySQL Yum Repository
https://dev.mysql.com/downloads/repo/yum/

本人这里用的是Red Hat Enterprise Linux 7 / Oracle Linux 7 (Architecture Independent), RPM Package

1.首先登录云服务器
2.下载rpm文件,可在任意文件夹下下载
地址更新 https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-community-server-5.7.31-1.el7.x86\_64.rpm
选择版本 https://dev.mysql.com/downloads/mysql/

  1. wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-community-server-5.7.31-1.el7.x86_64.rpm

3.安装rpm

  1. rpm -ivh mysql57-community-release-el7-11.noarch.rpm --force --nodeps

确认的时候输入y就好了,安装完成之后,在/etc/yum.repos.d目录下新增了两个文件,mysql-community.repo和mysql-community-source.repo
4.yum 安装mysql

  1. yum install mysql-community-server

5.启动mysql服务

  1. systemctl start mysqld

查看mysql状态

  1. systemctl status mysqld.service

6.设置mysql开机启动

  1. systemctl enable mysqld
  2. systemctl daemon-reload

7.查找root密码
mysql安装完成之后,在/var/log/mysqld.log文件中给root生成了一个默认密码。通过下面的方式找到root默认密码,然后登录mysql进行修改:

  1. grep 'temporary password' /var/log/mysqld.log

8.登录mysql,密码为刚才查找的密码

  1. mysql -u root -p

9.修改登录密码

  1. set password for 'root'@'localhost'=password('MyNewPass!');

备注:密码必须要包含大小写字符和数字,特殊字符也可以用,太简单会提示错误:Your password does not satisfy the current policy requirements
10.修改/etc/my.cnf配置文件,在[mysqld]下添加编码配置,如下所示:

[mysqld]
character_set_server=utf8
init_connect=‘SET NAMES utf8’

11.重启mysql

  1. systemctl restart mysqld

如需配置远程访问,请参考设置mysql允许外部连接访问

发表评论

表情:
评论列表 (有 0 条评论,368人围观)

还没有评论,来说两句吧...

相关阅读