mysql 离线安装
msyql离线安装
·
1.下载mysql离线安装包
下载页面:https://downloads.mysql.com/archives/community/
下载地址:https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.36-1.el7.x86_64.rpm-bundle.tar
2.上传到Centos7服务器,并解压
tar -xvf mysql-5.7.36-1.el7.x86_64.rpm-bundle.tar
3.安装mysql
# 1.先卸载服务器上的 mariadb 依赖
yum remove mariadb-libs
# 2.依次安装mysql rpm
rpm -ivh mysql-community-common-5.7.36-1.el7.x86_64.rpm;
rpm -ivh mysql-community-libs-5.7.36-1.el7.x86_64.rpm;
rpm -ivh mysql-community-libs-compat-5.7.36-1.el7.x86_64.rpm;
rpm -ivh mysql-community-devel-5.7.36-1.el7.x86_64.rpm;
rpm -ivh mysql-community-client-5.7.36-1.el7.x86_64.rpm;
rpm -ivh mysql-community-server-5.7.36-1.el7.x86_64.rpm --force --nodeps;
-
四个包安装完成后,启动mysql服务:
systemctl start mysqld
systemctl enable mysqld -
启动完成之后获取随机密码:grep ‘temporary password’ /var/log/mysqld.log
-
用随机密码登录mysql:mysql -uroot -p"密码"
-
进入MySQL终端修改密码
# 1.mysql密码安全规则(1.必须含有数字,小写或大写字母,特殊字符;2.最小长度为8)
set global validate_password_policy=0; #去掉1.必须含有数字,小写或大写字母,特殊字符规则
set global validate_password_length=1; #去掉2.最小长度为8规则
# 2.修改root密码
alter user 'root'@'localhost' identified by 'Root123456';
# 3.如果想root能远程访问
use mysql;
update user set host = '%' where user = 'root'; #使root能任何host访问
flush privileges; #刷新
- 创建一个mysql用户,并设置权限
# 3.创建用户和赋权限
use mysql;
# 3.1.创建一个新用户 admin 密码为 Admin123456.
CREATE USER 'admin'@'localhost' IDENTIFIED BY 'Admin123456.';
# 3.2.创建数据库testDB
create database testDB;
# 3.3.为testuser用户添加使用testDB权限
grant all privileges on testDB.* to admin@localhost identified by 'Admin123456.';
# 3.4.为testuser用户添加远程访问权限
GRANT ALL PRIVILEGES ON testDB.* TO 'admin'@'%' IDENTIFIED BY 'Admin123456.' WITH GRANT OPTION;
# 3.5.或者为用户添加所有数据库的权限
grant all on *.* to admin@'%' identified by 'Admin123456.';
# 3.6.刷新权限表,使命令生效
flush privileges;
查看MySQL状态:service mysqld status
重启MySQL状态:service mysqld restart
4.卸载mysql
//rpm包安装方式卸载
查包名:rpm -qa|grep -i mysql
删除命令:rpm -e –nodeps 包名
//yum安装方式下载
1.查看已安装的mysql
命令:rpm -qa | grep -i mysql
2.卸载mysql
命令:yum remove mysql-community-server-5.6.36-2.el7.x86_64
查看mysql的其它依赖:rpm -qa | grep -i mysql
//卸载依赖
yum remove mysql-libs
yum remove mysql-server
yum remove perl-DBD-MySQL
yum remove mysql
//删除残留文件(重要)
rm -f /var/log/mysqld.log
rm -rf /var/lib/mysql
5.注意事项
如果是MySQL8.0
注意,8.0版本这两个全局属性名称变化为: validate_password.policy和validate_password.length
所以修改命令为:
set global validate_password.policy=0;
set global validate_password.length=1;
再次修改就OK了
修改端口: vi /etc/my.cnf
port=3308
重启mysql:service mysqld restart ,如果报错,可能是selinux问题,执行:setenforce 0
点击阅读全文
更多推荐
活动日历
查看更多
直播时间 2025-02-26 16:00:00


直播时间 2025-01-08 16:30:00


直播时间 2024-12-11 16:30:00


直播时间 2024-11-27 16:30:00


直播时间 2024-11-21 16:30:00


所有评论(0)