一、yum安装
wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
rpm -Uvh mysql80-community-release-el7-3.noarch.rpm
yum install mysql-community-server
systemctl start mysqld
grep 'temporary password' /var/log/mysqld.log
2024-12-20T05:25:02.131962Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: f-?*e_fT_4hv #就是初始密码
二、二进制安装
#https://downloads.mysql.com/archives/community/ 官方文档,可以选择平台及版本 wget https://cdn.mysql.com/archives/mysql-8.0/mysql-8.0.25-linux-glibc2.12-x86_64.tar.xz tar xf mysql-8.0.25-linux-glibc2.12-x86_64.tar.xz -C /usr/local cd /usr/local mv mysql-8.0.25-linux-glibc2.12-x86_64/ mysql-8.0.25 cd mysql-8.0.25 useradd -s /sbin/nologin -M mysql chown -R mysql.mysql /usr/local/mysql-8.0.25/
vim /etc/my.cnf [mysqld] datadir=/var/lib/mysql log-error=/var/log/mysqld.log character-set-server=utf8mb4 default-storage-engine=INNODB [client] port=3306 default-character-set=utf8mb4
vim .bash_profile PATH=/usr/local/mysql-8.0.25/bin/:$PATH:$HOME/bin . .bash_profilemkdir /var/lib/mysql && chown -R mysql.mysql /var/lib/mysql
mysqld --initialize --console --user=mysql
cd support-files/ ./mysql.server start
grep 'temporary password' /var/log/mysqld.log
三、修改密码及创建用户并授权
mysql -hlocalhost -pALTER USER 'root'@'localhost' IDENTIFIED BY 'Fhk6P$TCwr&8T6mK'; #修改root密码及授权远程登录
UPDATE mysql.user SET host='%' WHERE user='root';CREATE USER 'user01'@'%' IDENTIFIED BY 'Fhk6P$TCwr&8T6mK'; #新建用户及授权
GRANT ALL PRIVILEGES ON *.* TO 'user01'@'%' WITH GRANT OPTION;
flush privileges;