CentOS7离线安装MySQL
删除原有的mariadb
- 查看安装的mariadb
rpm -qa|grep mariadb - 卸载mariadb
rpm -e --nodeps mariadb-libs
下载安装包
直接访问 https://dev.mysql.com/downloads/mysql/
选择为Red Hat Enterprise Linux 7 / Oracle Linux 7 ,把os的版本选择为all。
直接下载mysql-5.7.26-1.el7.x86_64.rpm-bundle.tar,所有的rpm包都在里面
rpm安装
- 下载的安装包上传到服务器
- 解压下载的mysql-5.7.26-1.el7.x86_64.rpm-bundle.tar
- 依次执行以下命令
rpm -ivh mysql-community-common-5.7.21-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.21-1.el7.x86_64.rpm
rpm -ivh mysql-community-devel-5.7.21-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-compat-5.7.21-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.21-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.21-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.26-1.el7.x86_64.rpm
warning: mysql-community-server-5.7.26-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
libaio.so.1()(64bit) is needed by mysql-community-server-5.7.26-1.el7.x86_64
libaio.so.1(LIBAIO_0.1)(64bit) is needed by mysql-community-server-5.7.26-1.el7.x86_64
libaio.so.1(LIBAIO_0.4)(64bit) is needed by mysql-community-server-5.7.26-1.el7.x86_64
遇到上述错误,需要安装libaio
yum install libaio.x86_64
重新安装server
至此,mysql5.7所有文件安装完毕,接下来就是开启服务测试了。
修改mysql配置文件
执行命令
vim /etc/my.cnf
- 无密码登录
# Disabling symbolic-links is recommended to prevent assorted security risks
skip-grant-tables #添加这句话,这时候登入mysql就不需要密码
symbolic-links=0
-
修改端口
在my.cnf里加上
port=你的端口 -
修改密码授权
-
开启mysql服务
service mysqld start
- 登录mysql
mysql -u root -p #输入命令回车进入,出现输入密码提示直接回车
mysql> set password for root@localhost = password('123456');
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
mysql> flush privileges; #更新权限
Query OK, 0 rows affected (0.00 sec)
mysql> set password for root@localhost = password('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql>flush privileges; #更新权限
mysql>quit; #退出
service mysqld stop # 停止mysql服务, 恢复mysql配置
vim /etc/my.cnf #修改配置文件
# Disabling symbolic-links is recommended to prevent assorted security risks
# skip-grant-tables # 注释掉这句话
symbolic-links=0
service mysqld start # 启动mysql服务
mysql -uroot -p # 输入新密码登录
设置开机自启
systemctl enable mysqld