下载安装包解压缩
wget http://mirrors.163.com/mysql/Downloads/MySQL-8.0/mysql-8.0.29-linux-glibc2.12-x86_64.tar
tar xvf mysql-8.0.29-linux-glibc2.12-x86_64.tar
tar xvf mysql-8.0.29-linux-glibc2.12-x86_64.tar.xz
mv mysql-8.0.29-linux-glibc2.12-x86_64 /usr/local/mysql
添加环境变量
cat > /etc/profile.d/mysql.sh << EOF
export PATH=/usr/local/mysql/bin:$PATH
EOF
chmod +x /etc/profile.d/mysql.sh
source /etc/profile
mysql --version
添加用户更改权限
groupadd mysql
useradd -r -g mysql mysql
chown -R mysql:mysql /usr/local/mysql
mkdir -p /data/mysql
chown -R mysql:mysql /data/mysql
开启防火墙
systemctl enable firewalld.service
systemctl restart firewalld.service
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload
firewall-cmd --zone=public --list-ports
创建 my.cnf
mkdir -p /etc/mysql
rm -rf /etc/my.cnf /etc/my.cnf.d
cat > /etc/mysql/my.cnf << EOF
[client]
port=3306
socket=/usr/local/mysql/mysql.sock
[mysql]
[mysqld]
datadir=/data/mysql
pid-file=/usr/local/mysql/mysql.pid
socket=/usr/local/mysql/mysql.sock
log-bin=/data/mysql/binlog
log-error=/data/mysql/error.log
server-id=73
binlog_format=row
gtid_mode=ON
enforce-gtid-consistency=ON
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
skip-character-set-client-handshake
open_files_limit=60000
max_connections=3000
innodb_buffer_pool_size=1G
max_connect_errors=100000
interactive_timeout=86400
wait_timeout=86400
binlog_cache_size=128M
max_binlog_cache_size=256M
max_binlog_size=1G
EOF
初始化
mysqld_safe --initialize
initPassword=`grep "A temporary password is generated" /data/mysql/error.log |tail -1 |awk '{print $NF}'`
更改启动脚本
vi /usr/local/mysql/support-files/mysql.server
basedir=/usr/local/mysql
datadir=/data/mysql
mysqld_pid_file_path=/usr/local/mysql
加入开机启动
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql
chkconfig --add mysql
启动
service mysql start
查看登录密码
cat /data/mysql/error.log | grep password
登录
mysql -u root -p;
更改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
添加远程 root 用户
CREATE USER 'root'@'%' IDENTIFIED BY 'bdZQT&root';
GRANT all privileges on *.* to root@'%';