Mysql centos 离线安装
卸载原有的MariaDB
# 查看系统自带的MariaDB [root@mysql_master ~]# rpm -qa |grep mariadb mariadb-libs-5.5.56-2.el7.x86_64 # 卸载系统自带的MariaDB [root@mysql_master ~]# rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64 # 删除 /etc/my.cnf配置文件 [root@mysql_master ~]# rm -rf /etc/my.cnf
1
2
3
4
5
6
7
8
9关闭防火墙
#查看防火墙状态 firewall-cmd --state #关闭防火墙 systemctl stop firewalld.service # 禁止防火墙开机自动启动 systemctl disable firewalld.service
1
2
3
4
5
6
7
8检查
# 执行下面的命令 没有返回值说明 MySQL不存在 rpm -qa |grep mysql
1
2创建msyql用户
# 创建MySQL用户组和用户 并在/home文件加下 创建mysql用户主目录 adduser mysql # 修改MySQL用户登录密码 按照提示输入两次密码即可 passwd mysql
1
2
3
4
5yum 先决条件
# 检查 rpm -qa | grep ncurses rpm -qa | grep libaio # 没有就安装 yum install libaio yum install numactl
1
2
3
4
5
6下载安装包
- https://mirrors.cloud.tencent.com/mysql/downloads/MySQL-5.7/mysql-5.7.34-1.el7.x86_64.rpm-bundle.tar
解压并安装
# 解压 tar -xvf mysql-5.7.22-1.el7.x86_64.rpm-bundle.tar # 安装(按顺序进行) rpm -ivh mysql-community-common-5.7.22-1.el7.x86_64.rpm rpm -ivh mysql-community-libs-5.7.22-1.el7.x86_64.rpm rpm -ivh mysql-community-client-5.7.22-1.el7.x86_64.rpm rpm -ivh mysql-community-server-5.7.22-1.el7.x86_64.rpm
1
2
3
4
5
6
7数据库初始化
mysqld --initialize #初始化后会在/var/log/mysqld.log生成随机密码
1修改mysql数据库目录的所属用户及其所属组, 并启动
chown mysql:mysql /var/lib/mysql -R systemctl start mysqld.service systemctl status mysqld.service
1
2
3查看初始密码
grep 'password' /var/log/mysqld.log
1登录mysql,并修改默认密码
mysql -uroot -p'-4iq<tyjVpLb' # 登录 # set password=password('msyql'); # 设置密码 set password for 'root'@'localhost'=password('msyql'); # 设置密码 #ALTER USER 'root'@'localhost' IDENTIFIED BY 'msyql'; # 设置密码 # update user set host='%',authentication_string=password('mysql') where user='root'; # 设置密码 flush privileges; # 刷新权限
1
2
3
4
5
6
7
8配置免密登录-可以忽略,一般用来修改密码
vim /etc/my.cnf [mysqld] skip-grant-tables systemctl restart mysqld.service mysql -u root -p use mysql; update user set host='%',authentication_string=password('mysql') where user='root'; flush privileges;
1
2
3
4
5
6
7
8
9
10
配置远程访问权限
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'mysql' WITH GRANT OPTION; flush privileges;
1
2创建用户和数据库并赋权
create user 'test'@'%' identified by 'test'; create database test_db; grant all on test_db.* to 'test'@'%';
1
2
3
上次更新: 2023/04/16, 18:35:33