1、下载mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz(/opt目录)
2、tar -zxvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
3、改名称。mv mysql-5.7.24-linux-glibc2.12-x86_64 mysql,在mysql目录下创建data目录,mkdir data
4、在/etc下新建my.cnf。内容如下
#[mysqld]
#datadir=/var/lib/mysql
#socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
#symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/opt/mysql/data/mysqld.pid
#
# include all files from the config directory
#
#!includedir /etc/my.cnf.d
[client]
port = 3306
socket = /opt/mysql/mysql.sock
default-character-set=utf-8
[mysqld]
#skip-grant-tables
character_set_server=utf8
init_connect='SET NAMES utf8'
basedir=/opt/mysql
datadir=/opt/mysql/data
socket=/opt/mysql/mysql.sock
lower_case_table_names = 1
bind-address = 0.0.0.0
sql_mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
5、在/opt/mysql下新建文件mysql.sock。
touch mysql.sock
chown mysql:mysql mysql.sock
chmod 755 mysql.sock
6、
查看组和用户情况:cat /etc/group | grep mysql
查看组和用户情况:cat /etc/passwd |grep mysql
若存在,则删除原mysql用户:userdel -r mysql,会删除其对应的组和用户并在次查看。
创建mysql组:groupadd mysql
创建mysql用户:useradd -r -g mysql mysql
修改目录拥有者:chown -R mysql:mysql /opt/mysql
7、cd /opt/mysql/bin/目录
./mysqld --user=mysql --basedir=/opt/mysql --datadir=/opt/mysql/data --initialize(需要记住初始密码)
8、./mysqld_safe --user=mysql &
9、./mysql -u root -p
输入初始密码
10、改密码:mysql>set password=password("123456");
11、mysql>grant all privileges on *.* to 'root'@'%' identified by '123456';
12、flush privileges;
13、set global show_compatibility_56=on;
14、mysql> quit;
15、cp -a /opt/mysql/support-files/mysql.server /etc/init.d/mysql
16、ln -s /opt/mysql/bin/mysql /usr/bin
参考:
https://www.cnblogs.com/songyinan/p/10093288.html
https://blog.csdn.net/demored/article/details/54341246