Centos7 安装 MySQL5.7 步骤
(一)、使用yum源方式安装
1、卸载系统自带 mariadb
[root@localhost /]# rpm -qa|grep mariadb
mariadb-libs-5.5.68-1.el7.x86_64
[root@localhost /]# rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64
[root@localhost /]# rpm -qa|grep mariadb
2、下载并安装MySQL官方的 Yum
2.1 下载mysql的yum源配置
[root@localhost ~]# wget http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
--2023-02-25 06:24:11-- https://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpm
正在解析主机 repo.mysql.com (repo.mysql.com)... 23.212.157.5
...
...
100%[=========================================================================>] 25,680 --.-K/s 用时 0s
2023-02-25 06:24:19 (180 MB/s) - 已保存 “mysql57-community-release-el7-11.noarch.rpm” [25680/25680])
[root@localhost ~]# ls
anaconda-ks.cfg mysql57-community-release-el7-11.noarch.rpm 模板 图片 下载 桌面
initial-setup-ks.cfg 公共 视频 文档 音乐
2.2 安装mysql的yum源
[root@localhost ~]# yum -y install mysql57-community-release-el7-11.noarch.rpm
已加载插件:fastestmirror, langpacks
正在检查 mysql57-community-release-el7-11.noarch.rpm: mysql57-community-release-el7-11.noarch
mysql57-community-release-el7-11.noarch.rpm 将被安装
...
...
已安装:
mysql57-community-release.noarch 0:el7-11
完毕!
[root@localhost ~]# ls /etc/yum.repos.d/
CentOS-Base.repo CentOS-fasttrack.repo CentOS-Vault.repo mysql-community-source.repo
CentOS-CR.repo CentOS-Media.repo CentOS-x86_64-kernel.repo
CentOS-Debuginfo.repo CentOS-Sources.repo mysql-community.repo
2.3 使用yum方式安装mysql
[root@localhost ~]# yum -y install mysql-server
2.3.1 安装过程中报错解决
警告:/var/cache/yum/x86_64/7/mysql57-community/packages/mysql-community-common-5.7.41-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID 3a79bd29: NOKEY
mysql-community-common-5.7.41-1.el7.x86_64.rpm 的公钥尚未安装
mysql-community-libs-compat-5.7.41-1.el7.x86_64.rpm 的公钥尚未安装
失败的软件包是:mysql-community-libs-compat-5.7.41-1.el7.x86_64
GPG 密钥配置为:file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
运行命令
[root@localhost ~]# rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
重新安装
[root@localhost ~]# yum -y install mysql-server
3、使用并设置mysql
3.1 启动mysql并查看状态
[root@localhost ~]# systemctl start mysqld.service
[root@localhost ~]# systemctl status mysqld.service
3.2 获取临时密码
[root@localhost ~]# cat /var/log/mysqld.log | grep password
2023-02-25T12:00:58.723624Z 1 [Note] A temporary password is generated for root@localhost: 1!L#qo3?d6i=
3.3 登录mysql
[root@localhost ~]# mysql -u root -p
Enter password:
3.4 修改登录密码
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Wxq3012@';
Query OK, 0 rows affected (0.00 sec)
4、设置远程访问
4.1 开启mysql的远程访问权限
mysql> grant all privileges on *.* to 'root'@'%' identified by 'Wxq3012@' with grant option;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
4.2 为firewalld添加开放端口3306
[root@localhost ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
success
重启配置
[root@localhost ~]# firewall-cmd --reload
success
4.3 远程连接测试
5、至此,mysql安装结束
完结,撒花
(二)、本地 tar 文件方式安装
1、获取tar安装包文件
1.1 下载mysql5.7安装包
1.2 包上传到 Linux 服务器
[root@localhost /]# cd /
[root@localhost /]# mkdir tools
[root@localhost /]# mkdir az
[root@localhost /]# ls /tools/
mysql-5.7.41-linux-glibc2.12-x86_64.tar
2、安装前查看设置
2.1 卸载 CentOS7 系统自带 mariadb
[root@localhost /]# rpm -qa|grep mariadb
mariadb-libs-5.5.68-1.el7.x86_64
[root@localhost /]# rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64
[root@localhost /]# rpm -qa|grep mariadb
2.2 检查系统是否安装过 MySQL
[root@localhost /]# rpm -qa | grep mysql
[root@localhost /]# whereis mysql
[root@localhost /]# find / -name mysql
2.3 检查有无 MySQL 用户组
[root@localhost /]# cat /etc/group | grep mysql
[root@localhost /]# cat /etc/passwd | grep mysql
- 创建 mysql 用户组和用户
[root@localhost /]# groupadd mysql
[root@localhost /]# useradd -r -g mysql mysql
3、安装 MySQL5.7
3.1 解压下载的tar文件
[root@localhost /]# mysql-5.7.41-linux-glibc2.12-x86_64.tar.gz
3.2 解压tar.gz文件
3.3 修改文件夹名称
[root@localhost az]# mv mysql-5.7.41-linux-glibc2.12-x86_64/ mysql5.7
[root@localhost az]# ls
mysql5.7
3.4 更改文件夹权限
[root@localhost az]# chown -R mysql:mysql /az/mysql5.7/
[root@localhost az]# chmod -R 755 /az/mysql5.7/
3.5 初始化mysql和获取密码
[root@localhost bin]# ./mysqld --initialize --user=mysql --datadir=/az/mysql5.7/data --basedir=/az/mysql5.7
2023-02-23T22:43:52.131986Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
...
...
2023-02-23T22:43:52.554378Z 1 [Note] A temporary password is generated for root@localhost: Pyq#VB8mieDS
3.6 编译my.cnf 配置文件
3.6.1 修改 my.cnf 配置文件
[root@localhost bin]# vim /etc/my.cnf
[mysqld]
datadir=/az/mysql5.7/data
port = 3306
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
symbolic-links=0
max_connections=400
innodb_file_per_table=1
表名存储在磁盘是小写的,但是比较的时候是不区分大小写
lower_case_table_names=1
3.6.1 修改 my.cnf 权限
[root@localhost bin]# chmod -R 755 /etc/my.cnf
3.7 编译mysql.server 文件
[root@localhost bin]# vim /az/mysql5.7/support-files/mysql.server
4、设置mysql服务
4.1 查询服务
[root@localhost ~]# ps -ef | grep mysql
root 2031 1778 0 06:27 pts/0 00:00:00 tar -x mysql-5.7.41-linux-glibc2.12-x86_64.tar
root 2396 1778 0 06:55 pts/0 00:00:00 grep --color=auto mysql
[root@localhost ~]# ps -ef | grep mysqld
root 2398 1778 0 06:55 pts/0 00:00:00 grep --color=auto mysqld
4.2 启动服务
[root@localhost ~]# /az/mysql5.7/support-files/mysql.server start
Starting MySQL.Logging to '/az/mysql5.7/data/localhost.localdomain.err'.
SUCCESS!
4.3 添加软连接,并重启服务
[root@localhost ~]# ln -s /az/mysql5.7/support-files/mysql.server /etc/init.d/mysql
[root@localhost ~]# ln -s /az/mysql5.7/bin/mysql /usr/bin/mysql
[root@localhost ~]# service mysql restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
[root@localhost ~]#
5、使用并设置mysql
5.1 登录mysql
[root@localhost ~]# mysql -u root -p
Enter password:
5.2 修改密码
mysql> set password for root@localhost = password('root');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql>
6、设置远程访问
6.1 开启mysql的远程访问权限
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update user set user.Host='%' where user.User='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
6.2 设置开机自启
将服务文件拷贝到init.d下,并重命名为mysql
[root@localhost ~]# cp /az/mysql5.7/support-files/mysql.server /etc/init.d/mysqld
赋予可执行权限
[root@localhost ~]# chmod +x /etc/init.d/mysqld
添加服务
[root@localhost ~]# chkconfig --add mysqld
显示服务列表
[root@localhost ~]# chkconfig --list
6.3 开放3306端口
开放3306端口命令
[root@localhost ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
success
重启防火墙
[root@localhost ~]# firewall-cmd --reload
success
6.4 远程连接测试
7、至此,mysql安装结束
完结,撒花
原文地址:https://blog.csdn.net/polaris3012/article/details/129216638
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.7code.cn/show_15811.html
如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除!
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。