- 在MySql官网获取Yum源
- 使用wget命令下载Mysql Yum源文件
wget https://repo.mysql.com//mysql80-community-release-el8-4.noarch.rpm
- 安装yum源
yum -y localinstall mysql80-community-release-el8-4.noarch.rpm
- 安装MySql
yum -y install mysql-community-server
- 启动MySql
systemctl start mysqld
- 设置开机启动
systemctl enable mysqld
systemctl daemon-reload
- 查看数据库初始root用户密码
cat /var/log/mysqld.log | grep password
- 登录数据库
mysql -uroot -p
- 修改密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的密码';
- 重新登录后,授权远程访问。
create user 'root'@'%' identified with mysql_native_password by '你的密码';
grant all privileges on *.* to 'root'@'%' with grant option;
flush privileges;
- 配置默认编码为UTF-8,修改/etc/my.cnf配置文件,在[mysqld]下添加编码配置
character_set_server=utf8
init_connect='SET NAMES utf8'
- 重启MySql服务
systemctl restart mysqld