目录规划
/mysql 软件目录
/data 数据目录/logs 日志目录

1.解压安装包

[root@mysql8 tmp]# tar xvf mysql-8.0.27-linux-glibc2.12-x86_64.tar.xz -C /
[root@mysql8 tmp]# mv /mysql-8.0.27-linux-glibc2.12-x86_64/ /mysql

2.创建Mysql组和mysql用户

[root@mysql8 tmp]# groupadd mysql;useradd -g mysql mysql

3.创建数据目录和日志目录

[root@mysql8 tmp]# mkdir /data
[root@mysql8 tmp]# mkdir /logs
[root@mysql8 tmp]# chown mysql.mysql /data/
[root@mysql8 tmp]# chown mysql.mysql /logs

4.编辑/etc/my.cnf

[client]
port=3306
socket=/tmp/mysql.sock

[mysqld]
port=3306
user=mysql
socket=/tmp/mysql.sock
basedir=/mysql
datadir=/data

5.初始化Mysql

[root@mysql8 tmp]# /mysql/bin/mysqld --initialize  --user=mysql --basedir=/mysql --datadir=/data
2021-10-24T13:54:13.276491Z 0 [System] [MY-013169] [Server] /mysql/bin/mysqld (mysqld 8.0.27) initializing of server in progress as process 1487
2021-10-24T13:54:13.310306Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-10-24T13:54:16.597922Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2021-10-24T13:54:20.492682Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1 is enabled for channel mysql_main
2021-10-24T13:54:20.492713Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1.1 is enabled for channel mysql_main
2021-10-24T13:54:20.520151Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: r04;%*ml*Fuv

6.拷贝mysql启动文件到系统初始化目录

[root@mysql8 tmp]# cp /mysql/support-files/mysql.server /etc/init.d/mysqld

7.启动mysql

[root@mysql8 tmp]# service mysqld start
Starting MySQL.Logging to '/data/mysql8.err'.
.. SUCCESS!

8.添加mysql环境变量

PATH=$PATH:$HOME/bin:/mysql/bin
export PATH

9.修改密码

[root@mysql8 tmp]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or /g.
Your MySQL connection id is 8
Server version: 8.0.27

Copyright (c) 2000, 2021, 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> alter user 'root'@'localhost' identified by 'wwwwww';
Query OK, 0 rows affected (0.03 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye
[root@mysql8 tmp]# mysql -uroot -pwwwwww
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 9
Server version: 8.0.27 MySQL Community Server - GPL

Copyright (c) 2000, 2021, 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>

版权声明:本文为博主原创文章,未经博主允许不得转载。

MYSQL