登录
首页 >  数据库 >  MySQL

MySQL 5.7安装(二进制安装包)

来源:SegmentFault

时间:2023-02-25 08:01:44 131浏览 收藏

编程并不是一个机械性的工作,而是需要有思考,有创新的工作,语法是固定的,但解决问题的思路则是依靠人的思维,这就需要我们坚持学习和更新自己的知识。今天golang学习网就整理分享《MySQL 5.7安装(二进制安装包)》,文章讲解的知识点主要包括MySQL,如果你对数据库方面的知识点感兴趣,就不要错过golang学习网,在这可以对大家的知识积累有所帮助,助力开发能力的提升。

一、准备环境

1、检查当前环境是否安装MySQL,如果有则删除卸载

rpm -qa | grep mysql
rpm -qa |grep mariadb
yum remove mariadb-libs-5.5.64-1.el7.x86_64

2、检查my.cnf文件,如果有则删除

rm /etc/my.cnf
rm /etc/mysql/my.cnf

二、下载安装MySQL

1、从官网下载MySQL5.7.34

1. 官网地址:https://downloads.mysql.com/archives/community
2. MySQL5.7.34 安装包下载地址:
https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz

2、安装MySQL 5.7.34

1.创建mysql用户
groupadd mysql
useradd -r -g mysql -s /bin/false mysql

2.解压安装包
cd /usr/local
tar zxvf mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz -C /usr/local
ln -s mysql-5.7.34-linux-glibc2.12-x86_64 mysql
cd mysql

3.创建run、logs路径
mkdir run && chown mysql.mysql run
mkdir logs && chown mysql.mysql logs
mkdir /data/mysql/data && chown mysql.mysql /data/mysql/data

4.初始化mysql
bin/mysqld --initialize --user=mysql --datadir=/data/mysql/data
[Note] A temporary password is generated for root@localhost: :qq:&XSwq6HL

5. 修改my.cnf配置文件
[mysqld]
port = 3306
socket = /usr/local/mysql/run/mysql.sock
pid_file = /usr/local/mysql/run/mysql.pid
datadir = /usr/local/mysql/data
character-set-server = utf8mb4

6.初次启动mysql,记录此命令返回的随机密码
bin/mysqld_safe --user=mysql &

7.创建启动脚本
cp support-files/mysql.server /etc/init.d/mysql.server
/etc/init.d/mysqld status  
/etc/init.d/mysqld start
/etc/init.d/mysqld stop
/etc/init.d/mysqld restart

8.设置mysql环境变量
echo 'export PATH=$PATH:/usr/local/mysql/bin' >> /etc/profile
source /etc/profile

3、修改MySQL密码,创建用户

mysql -u root -p':qq:&XSwq6HL'
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root-password';
CREATE USER 'root'@'127.0.0.1' IDENTIFIED BY 'root-password';
CREATE USER 'root'@'::1' IDENTIFIED BY 'root-password';
create user 'wayne'@'%' identified by '123';
grant select,update,insert,delete on test.* to 'wayne'@'%';

4、创建mysql配置文件

1.my.cnf 文件优先级
/etc/my.cnf  #Global options
/etc/mysql/my.cnf  #Global options
SYSCONFDIR/my.cnf  #Global options
$MYSQL_HOME/my.cnf  #Server-specific options (server only)

2./etc/mysql/my.cnf
[client]
user = root
password = 123456
port = 3306
socket = /usr/local/mysql/run/mysql.sock

[mysqld]
port = 3306
socket = /usr/local/mysql/run/mysql.sock
pid_file = /usr/local/mysql/run/mysql.pid
datadir = /usr/local/mysql/data
character-set-server = utf8mb4

5、重启mysql生效/etc/mysql/my.cnf

1.重启mysqld
/etc/init.d/mysqld restart
2.设置开机自启动mysqld
chkconfig --add mysqld

理论要掌握,实操不能落!以上关于《MySQL 5.7安装(二进制安装包)》的详细介绍,大家都掌握了吧!如果想要继续提升自己的能力,那么就来关注golang学习网公众号吧!

声明:本文转载于:SegmentFault 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>
评论列表