通用二进制安装MySQL 5.7

1、安装相关包

[root@centos79-mysql01 ~]# yum  install -y libaio numactl-libs

2、用户和组

[root@centos79-mysql01 ~]# groupadd -r mysql
[root@centos79-mysql01 ~]# useradd -r -g mysql -s /bin/false mysql

# /bin/false什么也不做只是返回一个错误状态,然后立即退出。
# 将用户的shell设置为/bin/false,用户会无法登录,并且不会有任何提示。

# /usr/sbin/nologin
# nologin会礼貌的向用户显示一条信息,并拒绝用户登录

3、准备程序文件

[root@centos79-mysql01 ~]# wget http://mirrors.tuna.tsinghua.edu.cn/mysql/downloads/MySQL-5.7/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz
[root@centos79-mysql01 ~]# tar xf mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz -C /usr/local/

[root@centos79-mysql01 ~]# cd /usr/local/

[root@centos79-mysql01 local]# ln -s mysql-5.7.38-linux-glibc2.12-x86_64 mysql
[root@centos79-mysql01 local]# chown -R root.root /usr/local/mysql/

[root@centos79-mysql01 local]# ll
total 0
drwxr-xr-x. 2 root root   6 Apr 11  2018 bin
drwxr-xr-x. 2 root root   6 Apr 11  2018 etc
drwxr-xr-x. 2 root root   6 Apr 11  2018 games
drwxr-xr-x. 2 root root   6 Apr 11  2018 include
drwxr-xr-x. 2 root root   6 Apr 11  2018 lib
drwxr-xr-x. 2 root root   6 Apr 11  2018 lib64
drwxr-xr-x. 2 root root   6 Apr 11  2018 libexec
lrwxrwxrwx  1 root root  35 Nov 15 18:18 mysql -> mysql-5.7.38-linux-glibc2.12-x86_64
drwxr-xr-x  9 root root 129 Nov 15 18:16 mysql-5.7.38-linux-glibc2.12-x86_64
drwxr-xr-x. 2 root root   6 Apr 11  2018 sbin
drwxr-xr-x. 5 root root  49 Nov  8 14:51 share
drwxr-xr-x. 2 root root   6 Apr 11  2018 src

4、准备环境变量

[root@centos79-mysql01 local]# echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@centos79-mysql01 local]# . /etc/profile.d/mysql.sh

5、准备配置文件

[root@centos79-mysql01 ~]# cp /etc/my.cnf{,.bak}

[root@centos79-mysql01 ~]# vim /etc/my.cnf
[mysqld]
datadir=/data/mysql
skip_name_resolve=1
socket=/data/mysql/mysql.sock
log-error=/data/mysql/mysql.log
pid-file=/data/mysql/mysql.pid
[client]
socket=/data/mysql/mysql.sock 

6、初始化数据库文件并提取root密码

# /data/mysql   会自动生成,但是/data/必须事先存在
[root@centos79-mysql01 ~]# mkdir -pv /data/mysql

# 生成 root 空密码
mysqld --initialize-insecure --user=mysql --datadir=/data/mysql

# 生成随机密码
[root@centos79-mysql01 ~]# mysqld --initialize --user=mysql --datadir=/data/mysql
[root@centos79-mysql01 ~]# grep password /data/mysql/mysql.log
2022-11-15T10:23:57.688586Z 1 [Note] A temporary password is generated for root@localhost: 9.NE>eed8dy)


7、准备服务脚本和启动

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

8、修改口令

#修改前面生成的随机密码为指定密码
[root@centos79-mysql01 ~]# mysqladmin -uroot -p'9.NE>eed8dy'   password Root123!

#修改前面生成的空密码为指定密码
[root@centos79-mysql01 ~]# mysqladmin -uroot   password  Root123!

9、测试登录

[root@centos79-mysql01 ~]# mysql -uroot -pRoot123!
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.38 MySQL Community Server (GPL)

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> status
--------------
mysql  Ver 14.14 Distrib 5.7.38, for linux-glibc2.12 (x86_64) using  EditLine wrapper

Connection id:		3
Current database:
Current user:		root@localhost
SSL:			Not in use
Current pager:		stdout
Using outfile:		''
Using delimiter:	;
Server version:		5.7.38 MySQL Community Server (GPL)
Protocol version:	10
Connection:		Localhost via UNIX socket
Server characterset:	latin1
Db     characterset:	latin1
Client characterset:	utf8
Conn.  characterset:	utf8
UNIX socket:		/data/mysql/mysql.sock
Uptime:			1 min 2 sec

Threads: 1  Questions: 9  Slow queries: 0  Opens: 106  Flush tables: 1  Open tables: 99  Queries per second avg: 0.145
--------------
© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享