#本段可直接复制粘贴#
#创建目录并下载mysql安装包
mkdir /usr/local/mysql
cd /usr/local/mysql/
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.21-linux-glibc2.12-x86_64.tar.xz
tar xf mysql-8.0.21-linux-glibc2.12-x86_64.tar.xz
mv mysql-8.0.21-linux-glibc2.12-x86_64 mysql-8.0.21
#创建用户与数据存储目录,并修改属组属主
mkdir /data
groupadd mysql
useradd -g mysql mysql
chown -R mysql.mysql /usr/local/mysql
cd bin/
#初始化
./mysqld --user=mysql --basedir=/usr/local/mysql/mysql-8.0.21 --datadir=/data/ --initialize
2. 配置mysql
#编辑my.cnf文件,配置如下
#cat /etc/my.cnf
[mysqld]
basedir=/usr/local/mysql/mysql-8.0.21
datadir=/data
#socket=/usr/local/mysql/mysql.sock
socket=/tmp/mysql.sock
character-set-server=UTF8MB4
# 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/mariadb/mariadb.log
#pid-file=/var/run/mariadb/mariadb.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
#将mysql.server放到/etc/init.d
cp -a ../support-files/mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql
ln -s /usr/local/mysql/mysql-8.0.21/bin/mysql /usr/bin
systemctl restart mysql
systemctl status mysql
3. 登录数据库
#修改root密码为111111
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '111111';
flush privileges;
use mysql;
//设置远程连接
update user set host='%' where user='root';
flush privileges;