一、上传软件并解压
[root@localhost opt]# cd /opt/
[root@localhost opt]# tar xf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
[root@localhost opt]# mv mysql-5.7.22-linux-glibc2.12-x86_64 /usr/local/mysql
二、创建管理用户
[root@localhost opt]# useradd mysql
三、创建目录并授权
[root@localhost opt]# mkdir -p /data/3306/data
[root@localhost opt]# chown -R mysql.mysql /data
四、清理环境 (清理系统默认安装的mariadb的数据库)
[root@localhost opt]# rpm -qa |grep mariadb
mariadb-libs-5.5.68-1.el7.x86_64
mariadb-5.5.68-1.el7.x86_64
[root@localhost opt]# yum remove mariadb-libs -y
[root@localhost opt]# ls /etc/my.*
ls: cannot access /etc/my.*: No such file or directory
五、初始化数据(系统数据)
添加环境变量
vim /etc/profile
#添加以下行:
export PATH=/usr/local/mysql/bin:$PATH
# 生效配置
[root@localhost opt]# source /etc/profile
#初始化
[root@localhost opt]# mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/3306/data
2021-07-22T08:17:48.328786Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-07-22T08:17:48.817843Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-07-22T08:17:48.896297Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-07-22T08:17:48.959484Z 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: 4d334564-eac5-11eb-892d-000c29a62278.
2021-07-22T08:17:48.960353Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-07-22T08:17:48.960928Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
六、创建配置文件
vim /etc/my.cnf
[mysqld]
user=mysql
basedir=/usr/local/mysql
datadir=/data/3306/data
socket=/tmp/mysql.sock
port=3306
[mysql]
socket=/tmp/mysql.sock
七、启动
[root@localhost opt]# cd /usr/local/mysql/support-files/
[root@localhost support-files]# ./mysql.server start
Starting MySQL.Logging to '/data/3306/data/localhost.localdomain.err'.
SUCCESS!
[root@localhost support-files]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost support-files]# service mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
修改密码
[root@localhost support-files]# mysql
mysql> alter user root@'localhost' identified by '123';
网友评论