CentOS 7.6 安装与配置 MySql 5.7.40
Posted 程序员大宝(coder-dabao)
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CentOS 7.6 安装与配置 MySql 5.7.40相关的知识,希望对你有一定的参考价值。
1 通过wget下载mysql的rpm
# wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
2 检查是否存在MySql的repo
# cd /etc/yum.repos.d/
# ls
CentOS-Base.repo CentOS-Epel.repo
可以看到没有MySql的repo
3 安装MySql的repo,并查看是否安装成功
安装
# rpm -ivh /tmp/mysql57-community-release-el7-9.noarch.rpm
检查
[root@VM-12-7-centos yum.repos.d]# cd /etc/yum.repos.d/
[root@VM-12-7-centos yum.repos.d]# ll
总用量 16
-rw-r--r-- 1 root root 614 12月 25 2021 CentOS-Base.repo
-rw-r--r-- 1 root root 230 12月 25 2021 CentOS-Epel.repo
-rw-r--r-- 1 root root 1416 9月 12 2016 mysql-community.repo
-rw-r--r-- 1 root root 1440 9月 12 2016 mysql-community-source.repo
[root@VM-12-7-centos yum.repos.d]#
4 查看系统原来是否存在MySql包
[root@VM-12-7-centos yum.repos.d]# rpm -qa | grep mysql
mysql57-community-release-el7-9.noarch
[root@VM-12-7-centos yum.repos.d]#
可以看到只有我们刚才安装的包,没有其他的mysql包
5 安装MySql
忽略GPG检查。否则会报错。
# yum install -y mysql-server --nogpgcheck
6 修改数据目录
# mkdir -p /data/apps/mysql
vi /etc/my.cnf
将datadir的值从/var/lib/mysql变成自己的数据目录/data/apps/mysql
datadir=/data/apps/mysql
7 启动MySql服务并查看启动状态
7.1 启动
# systemctl start mysqld
7.2 状态
# systemctl status mysqld
7.3 停止
# systemctl stop mysqld
7.4 开机启动
# systemctl enable mysqld
# systemctl daemon-reload
8 初始密码
# grep "password" /var/log/mysqld.log
9 登录与重置密码
登录
# mysql -uroot -p
重置密码
mysql> alter user 'root'@'localhost' identified by "HaiMy$2022****";
mysql> flush privileges;
10 开放访问权限
1)公网账号(%:全部ip)
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'xxxxxx' WITH GRANT OPTION;
mysql> flush privileges;
mysql> grant ALTER,CREATE,DELETE,INDEX,INSERT,SELECT,UPDATE on *.* to 'ww_admin'@'%' IDENTIFIED BY 'b@xxxx555666' WITH GRANT OPTION;
mysql> flush privileges;
mysql> grant SELECT on *.* to 'ww_select'@'%' IDENTIFIED BY 'b@xxxx555888' WITH GRANT OPTION;
mysql> flush privileges;
2)内网账号(10.0.%开头的ip)
mysql> grant DELETE,INSERT,SELECT,UPDATE on *.* to 'nw_rw'@'10.0.%' IDENTIFIED BY 'b@xxxx555111' WITH GRANT OPTION;
mysql> flush privileges;
mysql> grant SELECT,INSERT,DELETE,UPDATE on `nacos`.* to 'nacos'@'10.0.%' IDENTIFIED BY 'b@xxxx555222' WITH GRANT OPTION;
mysql> flush privileges;
11 查看版本
mysql> select version();
+-----------+
| version() |
+-----------+
| 5.7.40 |
+-----------+
1 row in set (0.00 sec)
mysql>
12 参考文档
1、《腾讯云轻量服务器Centos 7.6通过rpm安装MySql 5.7.37》:https://blog.csdn.net/cssweb_sh/article/details/123599846
2、《【腾讯云】CentOS7.6系统环境下安装并配置MySQL5.7,实现远程登录》:https://blog.csdn.net/weixin_43805939/article/details/127534346
以上是关于CentOS 7.6 安装与配置 MySql 5.7.40的主要内容,如果未能解决你的问题,请参考以下文章