关于mysql:MySQL-57安装二进制安装包

48次阅读

共计 1687 个字符,预计需要花费 5 分钟才能阅读完成。

一、筹备环境

1、查看以后环境是否装置 MySQL,如果有则删除卸载

rpm -qa | grep mysql
pm -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

4. 初始化 mysql
bin/mysqld --initialize --user=mysql

5. 首次启动 mysql,记录此命令返回的随机明码
bin/mysqld_safe --user=mysql &
[Note] A temporary password is generated for root@localhost: :qq:&XSwq6HL

6. 创立启动脚本
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

7. 设置 mysql 环境变量
echo 'export PATH=$PATH:/usr/local/mysql/bin' >> /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';

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

/etc/init.d/mysqld restart

正文完
 0