【√】MySQL安装-RPM
带有【√】博客的安装包
链接: https://pan.baidu.com/s/1Wxo4C7czkK0Ww5YYdYsE6g 提取码: imx7
1. 查看CentOS是否自带的MySQL环境
rpm -qa | grep -i mysql
rpm -qa | grep -i mariadb
2. 卸载mariadb
rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64
3. 解压文件
mkdir -p /创建解压目录
tar -zxvf /root/mysql-5.7.25-1.el7.x86_64.rpm-bundle.tar.gz -C /解压到你的剥
cd /切换到你的目录进行rpm安装
4. 安装libaio环境(已经存在不需要)
yum install libaio
5. 安装MySQL(必须按顺序)
此处的安装必须与解压路径相同 /你的解压目录
例如 rpm -ivh /你的解压目录/mysql-community-common-5.7.25-1.el7.x86_64.rpm
rpm -ivh /mysql-community-common-5.7.25-1.el7.x86_64.rpm
rpm -ivh /mysql-community-libs-5.7.25-1.el7.x86_64.rpm
rpm -ivh /mysql-community-devel-5.7.25-1.el7.x86_64.rpm
rpm -ivh /mysql-community-libs-compat-5.7.25-1.el7.x86_64.rpm
rpm -ivh /mysql-community-client-5.7.25-1.el7.x86_64.rpm
rpm -ivh /mysql-community-server-5.7.25-1.el7.x86_64.rpm
最后一个rpm安装时报错
缺少依赖,执行
yum install libnuma*
6. 启动mysql服务
systemctl start mysqld
7. 查看随机生成的密码
grep 'password' /var/log/mysqld.log
8. 修改root用户密码
mysql -u root -p
Enter password:输入刚才查询到的随机密码
>set global validate_password_length=4;
>set global validate_password_policy=LOW;
>set password = password('root');
9. 防火墙放行端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload
10. 开启mysql的远程登录权限
MySQL 8.0不支持下面这种命令写法 grant all privileges on *.* to root@"%" identified by ".";
mysql -uroot -proot
> CREATE USER 'root'@'%' IDENTIFIED BY 'root';
> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' ;
> FLUSH PRIVILEGES;
> exit;
9. 防火墙放行端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload
10. 开启mysql的远程登录权限
mysql -uroot -proot
> CREATE USER 'root'@'%' IDENTIFIED BY 'root';
> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';
> FLUSH PRIVILEGES;
> exit;
11. MySQL编码问题(默认安装完毕为 ISO-8859-1)
1. 编辑/etc/my.cnf,在[mysqld]选项下添加字符集的设置
vim /etc/my.cnf
[mysqld]
character-set-server=utf8
2. 重新启动mysql的服务
systemctl restart mysqld