Centos7二进制搭建MySQL 5.7

首先下载MySQL 5.7二进制包

wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.27-linux-glibc2.12-x86_64.tar.gz

##创建用户
groupadd mysql
useradd -g mysql -s /sbin/nologin mysql

##解压安装
tar zxf mysql-5.7.27-linux-glibc2.12-x86_64.tar.gz -C /usr/local

##建立软链接
cd /usr/local
ln -s mysql-5.7.27-linux-glibc2.12-x86_64 mysql

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

 ##配置MySQL把mysql数据放在/data/mysql目录,创建目录并赋予权限


mkdir -pv /data/mysql
chown mysql.mysql /data/mysql
chmod go-rwx /data/mysql

[root@localhost local]# mkdir -pv /data/mysql
mkdir: 已创建目录 "/data"
mkdir: 已创建目录 "/data/mysql"
[root@localhost local]# chown mysql.mysql /data/mysql
[root@localhost local]# chmod go-rwx /data/mysql

###配置my.cnf

vim /etc/my.cnf
[client]
port = 3306
socket = /tmp/mysql.sock
 
[mysqld]
port = 3306
socket = /tmp/mysql.sock
pid_file = /data/mysql/mysql.pid
datadir = /data/mysql
default_storage_engine = InnoDB
max_allowed_packet = 512M
max_connections = 2048
open_files_limit = 65535
 
character-set-server = utf8
innodb_buffer_pool_size = 512M
innodb_log_file_size = 1024M
innodb_file_per_table = 1
innodb_flush_log_at_trx_commit = 0
key_buffer_size = 64M
 log-error = /data/mysql/mysql_error.log
log-bin = /data/mysql/mysql-bin
binlog_format = mixed
expire_logs_days = 10

slow_query_log = 1
slow_query_log_file = /data/mysql/slow_query.log
long_query_time = 1
 
server-id=1

 执行初始化命令,执行完会在 /data/mysql 生成数据文件

mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql

cat /data/mysql/mysql_error.log  在日志文件里会提示一个临时密码

 [Note] A temporary password is generated for root@localhost: 4359d1jsv4!D
 

[root@localhost mysql]# cat /data/mysql/mysql_error.log  
2022-06-17T08:14:33.341019Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
 100 200 300 400 500 600 700 800 900 1000
 100 200 300 400 500 600 700 800 900 1000
2022-06-17T08:14:36.712971Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-06-17T08:14:36.753055Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-06-17T08:14:36.832529Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 8700866f-ee15-11ec-9009-000c29e8f9a4.
2022-06-17T08:14:36.832982Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-06-17T08:14:36.834035Z 1 [Note] A temporary password is generated for root@localhost: 4359d1jsv4!D


##配置启动脚本

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig  mysqld on
chkconfig --list |grep mysqld
 

[root@localhost mysql]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql]# chkconfig --add mysqld
[root@localhost mysql]# chkconfig  mysqld on
[root@localhost mysql]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS! 
[root@localhost mysql]# 


##启动MySQL
/etc/init.d/mysqld start

看到进程说明启动成功

登录和重置root密码
mysql -u root -p 
输入临时密码

mysql>set password for root@localhost = password('Admin@1234'); 
安装完成。

[root@localhost mysql]# mysql -u root -p 
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.27-log

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

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> set password for root@localhost = password('Admin@1234'); 
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

机灵的小小子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值