腾讯云轻量服务器Centos 7.6通过rpm安装MySql 5.7.37
2022/3/20 2:28:30
本文主要是介绍腾讯云轻量服务器Centos 7.6通过rpm安装MySql 5.7.37,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
1. 通过wget下载MySql的rpm
[root@VM-4-16-centos ~]# wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
下载完成后是这样的:
2. 检查是否存在MySql的repo
[root@VM-4-16-centos ~]# cd /etc/yum.repos.d/ [root@VM-4-16-centos yum.repos.d]# ls CentOS-Base.repo CentOS-Epel.repo
可以看到没有MySql的repo
3. 安装MySql的repo,并查看是否安装成功
[root@VM-4-16-centos ~]# rpm -ivh mysql57-community-release-el7-9.noarch.rpm 警告:mysql57-community-release-el7-9.noarch.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY 准备中... ################################# [100%] 正在升级/安装... 1:mysql57-community-release-el7-9 ################################# [100%] [root@VM-4-16-centos ~]# cd - [root@VM-4-16-centos yum.repos.d]# ls CentOS-Base.repo CentOS-Epel.repo mysql-community.repo mysql-community-source.repo
4. 查看系统原来是否存在MySql包
[root@VM-4-16-centos yum.repos.d]# rpm -qa | grep mysql mysql57-community-release-el7-9.noarch
可以看到只有我们刚才安装的包,没有其他的mysql包
5. 安装MySql
[root@VM-4-16-centos ~]# yum install -y mysql-server
执行命令后,正常下载即可,但是下载完后会有个告警
失败的软件包是:mysql-community-libs-compat-5.7.37-1.el7.x86_64
GPG 密钥配置为:file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
处理办法:修改 /etc/yum.repos.d/mysql-community.repo,找到你安装的MySql版本。修改其中的gpgcheck=0
即可,默认值为1
[root@VM-4-16-centos yum.repos.d]# vim /etc/yum.repos.d/mysql-community.repo
修改前:
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
修改后:
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
6. 启动MySql服务并查看启动状态
# 启动mMysql [root@VM-4-16-centos yum.repos.d]# systemctl start mysqld # 查看启动状态 [root@VM-4-16-centos ~]# systemctl status mysqld ● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since 六 2022-03-19 18:56:11 CST; 28min ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Process: 17643 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS) Process: 17579 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS) Main PID: 17647 (mysqld) CGroup: /system.slice/mysqld.service └─17647 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid 3月 19 18:56:06 VM-4-16-centos systemd[1]: Starting MySQL Server... 3月 19 18:56:11 VM-4-16-centos systemd[1]: Started MySQL Server.
runing表示已经启动
7. 查看MySql的版本号
[root@VM-4-16-centos ~]# mysql -V mysql Ver 14.14 Distrib 5.7.37, for Linux (x86_64) using EditLine wrapper
8. 查看MySql初始密码
[root@VM-4-16-centos ~]# vim /etc/my.cnf
通过my.cnf文件找到log-error=/var/log/mysqld.log文件,在改文件中根据password关键字查询初始密码
[root@VM-4-16-centos ~]# grep "password" /var/log/mysqld.log
找到初始密码之后,就可以开始登录了
9. 登录MySql
[root@VM-4-16-centos ~]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.7.37 Copyright (c) 2000, 2022, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
Enter password: 这里输入密码即可,出现mysql>表示已经登录成功
10. 修改登录密码
mysql> alter user 'root'@'localhost' identified by "xxxxxx";
xxxxxx表示需要修改的密码
11. 开放连接权限
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'xxxxxx' WITH GRANT OPTION;
xxxxxx是指root的密码
以上就是centos7.6安装MySql5.7+的步骤
这篇关于腾讯云轻量服务器Centos 7.6通过rpm安装MySql 5.7.37的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-25如何部署MySQL集群资料:新手入门教程
- 2024-12-24MySQL集群部署资料:新手入门教程
- 2024-12-24MySQL集群资料详解:新手入门教程
- 2024-12-24MySQL集群部署入门教程
- 2024-12-24部署MySQL集群学习:新手入门教程
- 2024-12-24部署MySQL集群入门:一步一步搭建指南
- 2024-12-07MySQL读写分离入门:轻松掌握数据库读写分离技术
- 2024-12-07MySQL读写分离入门教程
- 2024-12-07MySQL分库分表入门详解
- 2024-12-07MySQL分库分表入门指南