centos7安装mysql5.7.40

centos7安装mysql5.7.40

1.先去下载安装包

下载地址
Tip:使用迅雷下载会快一点
在这里插入图片描述

2.创建一个mysql用户

groupadd mysql
useradd -g mysql -s /sbin/nologin mysqln

3.安装mysql依赖包

yum install -y ncurses-devel libaio-devel gcc gcc-c++ numactl libaio glibc cmake autoconf

4.解压mysql

[root@localhost mysql]# ls
mysql-5.7.40-linux-glibc2.12-x86_64.tar.gz
[root@localhost mysql]# tar -zxvf mysql-5.7.40-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
mysql-5.7.40-linux-glibc2.12-x86_64/bin/myisam_ftdump
mysql-5.7.40-linux-glibc2.12-x86_64/bin/myisamchk
mysql-5.7.40-linux-glibc2.12-x86_64/bin/myisamlog
mysql-5.7.40-linux-glibc2.12-x86_64/bin/myisampack
mysql-5.7.40-linux-glibc2.12-x86_64/bin/mysql
mysql-5.7.40-linux-glibc2.12-x86_64/bin/mysql_client_test_embedded
mysql-5.7.40-linux-glibc2.12-x86_64/bin/mysql_config_editor
mysql-5.7.40-linux-glibc2.12-x86_64/bin/mysql_embedded

解压完成之后进入/usr/local

5.修改名字为mysql5.7.40

[root@localhost local]# ls
bin  etc  games  include  lib  lib64  libexec  mysql-5.7.40-linux-glibc2.12-x86_64  sbin  share  src
[root@localhost local]# pwd
/usr/local
[root@localhost local]# ls
bin  etc  games  include  lib  lib64  libexec  mysql-5.7.40-linux-glibc2.12-x86_64  sbin  share  src
[root@localhost local]# mv mysql-5.7.40-linux-glibc2.12-x86_64/ mysql5.7.40
[root@localhost local]# ls
bin  etc  games  include  lib  lib64  libexec  mysql5.7.40  sbin  share  src
[root@localhost local]# 

6.修改环境变量

echo "export PATH=$PATH:/usr/local/mysql5.7.40/bin" >> /etc/profile
source /etc/profile

7.修改目录所属用户权限

[root@localhost local]# ls
bin  etc  games  include  lib  lib64  libexec  mysql5.7.40  sbin  share  src
[root@localhost local]# chown -R mysql.mysql mysql5.7.40/
[root@localhost local]# ll
总用量 0
drwxr-xr-x. 2 root  root    6 411 2018 bin
drwxr-xr-x. 2 root  root    6 411 2018 etc
drwxr-xr-x. 2 root  root    6 411 2018 games
drwxr-xr-x. 2 root  root    6 411 2018 include
drwxr-xr-x. 2 root  root    6 411 2018 lib
drwxr-xr-x. 2 root  root    6 411 2018 lib64
drwxr-xr-x. 2 root  root    6 411 2018 libexec
drwxr-xr-x  9 mysql mysql 129 317 18:33 mysql5.7.40
drwxr-xr-x. 2 root  root    6 411 2018 sbin
drwxr-xr-x. 5 root  root   49 216 18:20 share
drwxr-xr-x. 2 root  root    6 411 2018 src
[root@localhost local]# 

8.创建存储数据的位置以及日志

在根目录创建 /mysql

mkdir /msyql

然后进入 /mysql

mkdir mysql_data
chown -R mysql:mysql mysql_data/
touch mysqld.log
chown -R mysql:mysql mysqld.log

结果如下

[root@localhost mysql]# ll
总用量 1258124
-rw-r--r-- 1 root  root  678001736 317 18:26 mysql-5.7.40-linux-glibc2.12-x86_64.tar.gz
drwxr-xr-x 2 mysql mysql         6 317 18:51 mysql_data
-rw-r--r-- 1 mysql mysql         0 317 18:52 mysqld.log

9.初始化mysql

cd /usr/local/mysql5.7.40
# 初始化命令 datadir为上面步骤创建存放数据的位置
bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql5.7.40/ --datadir=/mysql/mysql_data/

初始化完成

[root@localhost mysql5.7.40]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql5.7.40/ --datadir=/mysql/mysql_data/
2023-03-22T09:40:27.256362Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2023-03-22T09:40:27.665979Z 0 [Warning] InnoDB: New log files created, LSN=45790
2023-03-22T09:40:27.801258Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2023-03-22T09:40:27.887321Z 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: 941b9bac-c895-11ed-9069-000c29f766f6.
2023-03-22T09:40:27.890207Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2023-03-22T09:40:28.178688Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2023-03-22T09:40:28.178708Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2023-03-22T09:40:28.179324Z 0 [Warning] CA certificate ca.pem is self signed.
2023-03-22T09:40:28.274175Z 1 [Note] A temporary password is generated for root@localhost: 1g%ddU71Vkum

结尾的:1g%ddU71Vkum 是初始化密码

10.创建日志文件等

cd /usr/local/mysql5.7.40/
mkdir run 
cd run/
touch mysqld.pid  mysql.sock
cd ..
mkdir log
touch mysql_error.log

11.配置my.cnf文件

修改 /etc/my.cnf
先移动下系统的做备份,之后再创建新的配置文件去编写

mv my.cnf A_mysql.cof
vim /etc/my.cnf
[mysqld]
basedir=/usr/local/mysql5.7.40
datadir=/mysql/mysql_data
port=3306
socket=/usr/local/mysql5.7.40/mysql.sock
character-set-server=utf8mb4
log-error=/var/log/mysqld.log
pid-file=/tmp/mysqld.pid
[mysql]
socket=/usr/local/mysql5.7.40/mysql.sock
[client]
socket=/usr/local/mysql5.7.40/mysql.sock

12.编辑mysql.server

# 先移动
cp /usr/local/mysql5.7.40/support-files/mysql.server /etc/init.d/mysqld
# 添加执行权限
chmod +x /etc/init.d/mysqld
# 修改文件信息 主要修改 basedir(mysql路径) 与 datadir(数据路径)
vim /etc/init.d/mysqld
basedir=/usr/local/mysql5.7.40
datadir=/mysql/mysql_data

在这里插入图片描述

13.启动mysql

/etc/init.d/mysqld start
[root@localhost init.d]# /etc/init.d/mysqld start
Starting MySQL.Logging to '/mysql/mysql_data/localhost.localdomain.err'.
 SUCCESS! 

14.登录mysql

mysql -u root -p
# 之后输入初始密码 1g%ddU71Vkum
[root@localhost mysql5.7.40]# 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.40

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> 

15.修改新密码

新密码为123456

set password for root@localhost = password('123456');

16.将myslq加入systemctl管理

vim /usr/lib/systemd/system/mysql.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=https://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/usr/local/mysql5.7.40/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
# 重载
systemctl daemon-reload
# 开启mysql服务
systemctl start mysql
查看状态
# systemctl status mysql

在这里插入图片描述
至此结束!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值