前些日子用linux安装mysql,废了好大劲,用yum一直不成功,最后查了好多资料改为用rpm安装了,还是手动安装靠谱。
--------------------------------------------
环境介绍:
操作系统:Centos 7.2
mysql数据库版本:mysql5.7
---------------------------------------------------
1、在安装mysql前,首先需要将系统自带的mariadb-lib卸载
[root@localhost ~]# rpm -qa|grep mariadb
mariadb-libs-5.5.44-2.el7.centos.x86_64
[root@localhost ~]# rpm -e mariadb-libs-5.5.44-2.el7.centos.x86_64 --nodeps
[root@localhost ~]#
2、在mysql官网上下载最新的mysql的rpm的集合包:mysql-5.7.17-1.el7.x86_64.rpm-bundle.tar
[root@localhost downloads]# wget -c https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.17-1.el7.x86_64.rpm-bundle.tar
3、将下载好的mysql集合包解压
[root@localhost downloads]# tar -xvf mysql-5.7.17-1.el7.x86_64.rpm-bundle.tar
mysql-community-embedded-compat-5.7.17-1.el7.x86_64.rpm
mysql-community-libs-5.7.17-1.el7.x86_64.rpm
mysql-community-common-5.7.17-1.el7.x86_64.rpm
wo-5.7.17-1.el7.x86_64.rpm
mysql-community-client-5.7.17-1.el7.x86_64.rpm
mysql-community-server-5.7.17-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.17-1.el7.x86_64.rpm
mysql-community-server-minimal-5.7.17-1.el7.x86_64.rpm
mysql-community-embedded-devel-5.7.17-1.el7.x86_64.rpm
mysql-community-test-5.7.17-1.el7.x86_64.rpm
mysql-community-minimal-debuginfo-5.7.17-1.el7.x86_64.rpm
mysql-community-embedded-5.7.17-1.el7.x86_64.rpm
安装最基本的mysql server服务只需要上面标红的四个包
libs依赖于common,client依赖于libs,server依赖于client和common
4、使用命令 rpm -ivh *.rpm 进行安装
[root@localhost downloads]# rpm -ivh mysql-community-common-5.7.17-1.el7.x86_64.rpm
警告:mysql-community-common-5.7.17-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-common-5.7.17-1.e################################# [100%]
[root@localhost downloads]# rpm -ivh mysql-community-libs-5.7.17-1.el7.x86_64.rpm
警告:mysql-community-libs-5.7.17-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-libs-5.7.17-1.el7################################# [100%]
[root@localhost downloads]# rpm -ivh mysql-community-client-5.7.17-1.el7.x86_64.rpm
警告:mysql-community-client-5.7.17-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-client-5.7.17-1.e################################# [100%]
如果在安装mysql-server中遇到了net-tools没有的错误,重新下一个就好
[root@localhost downloads]# rpm -ivh mysql-community-server-5.7.17-1.el7.x86_64.rpm
警告:mysql-community-server-5.7.17-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
错误:依赖检测失败:
net-tools 被 mysql-community-server-5.7.17-1.el7.x86_64 需要
[root@localhost downloads]# yum install net-tools
安装好后,继续安装mysql-server就好
[root@localhost downloads]# rpm -ivh mysql-community-server-5.7.17-1.el7.x86_64.rpm
警告:mysql-community-server-5.7.17-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-server-5.7.17-1.e################################# [100%]
5、初始化mysql
[root@localhost ~]# mysqld --initialize
mysql会在
/
var/log/mysqld.log生成一个随机密码
6、修改mysql所属用户和组
[root@localhost ~]# chown mysql:mysql /var/lib/mysql -R
7、启动mysql服务
[root@localhost ~]# systemctl start mysqld.service
systemctl 是centos最新的启动服务方式
8、使用第6步找到的密码进行mysql登录操作
[root@localhost ~]# mysql -uroot -p'yourpassword'
9、登陆进去后 修改root的密码
mysql> set password=password('1992917ab');
Query OK, 0 rows affected, 1 warning (0.00 sec)
10、创建新用户并刷新权限
mysql> create user 'admin'@'%' identified by '123456';
Query OK, 0 rows affected (0.00 sec)
mysql> GRANT ALL PRIVILEGES ON *.* to 'admin'@'%';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
[root@localhost ~]# rpm -qa|grep mariadb
mariadb-libs-5.5.44-2.el7.centos.x86_64
[root@localhost ~]# rpm -e mariadb-libs-5.5.44-2.el7.centos.x86_64 --nodeps
[root@localhost ~]#
2、在mysql官网上下载最新的mysql的rpm的集合包:mysql-5.7.17-1.el7.x86_64.rpm-bundle.tar
[root@localhost downloads]# wget -c https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.17-1.el7.x86_64.rpm-bundle.tar
3、将下载好的mysql集合包解压
[root@localhost downloads]# tar -xvf mysql-5.7.17-1.el7.x86_64.rpm-bundle.tar
mysql-community-embedded-compat-5.7.17-1.el7.x86_64.rpm
mysql-community-libs-5.7.17-1.el7.x86_64.rpm
mysql-community-common-5.7.17-1.el7.x86_64.rpm
wo-5.7.17-1.el7.x86_64.rpm
mysql-community-client-5.7.17-1.el7.x86_64.rpm
mysql-community-server-5.7.17-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.17-1.el7.x86_64.rpm
mysql-community-server-minimal-5.7.17-1.el7.x86_64.rpm
mysql-community-embedded-devel-5.7.17-1.el7.x86_64.rpm
mysql-community-test-5.7.17-1.el7.x86_64.rpm
mysql-community-minimal-debuginfo-5.7.17-1.el7.x86_64.rpm
mysql-community-embedded-5.7.17-1.el7.x86_64.rpm
安装最基本的mysql server服务只需要上面标红的四个包
libs依赖于common,client依赖于libs,server依赖于client和common
4、使用命令 rpm -ivh *.rpm 进行安装
[root@localhost downloads]# rpm -ivh mysql-community-common-5.7.17-1.el7.x86_64.rpm
警告:mysql-community-common-5.7.17-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-common-5.7.17-1.e################################# [100%]
[root@localhost downloads]# rpm -ivh mysql-community-libs-5.7.17-1.el7.x86_64.rpm
警告:mysql-community-libs-5.7.17-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-libs-5.7.17-1.el7################################# [100%]
[root@localhost downloads]# rpm -ivh mysql-community-client-5.7.17-1.el7.x86_64.rpm
警告:mysql-community-client-5.7.17-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-client-5.7.17-1.e################################# [100%]
如果在安装mysql-server中遇到了net-tools没有的错误,重新下一个就好
[root@localhost downloads]# rpm -ivh mysql-community-server-5.7.17-1.el7.x86_64.rpm
警告:mysql-community-server-5.7.17-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
错误:依赖检测失败:
net-tools 被 mysql-community-server-5.7.17-1.el7.x86_64 需要
[root@localhost downloads]# yum install net-tools
安装好后,继续安装mysql-server就好
[root@localhost downloads]# rpm -ivh mysql-community-server-5.7.17-1.el7.x86_64.rpm
警告:mysql-community-server-5.7.17-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-server-5.7.17-1.e################################# [100%]
5、初始化mysql
[root@localhost ~]# mysqld --initialize
mysql会在
/
var/log/mysqld.log生成一个随机密码
6、修改mysql所属用户和组
[root@localhost ~]# chown mysql:mysql /var/lib/mysql -R
7、启动mysql服务
[root@localhost ~]# systemctl start mysqld.service
systemctl 是centos最新的启动服务方式
8、使用第6步找到的密码进行mysql登录操作
[root@localhost ~]# mysql -uroot -p'yourpassword'
9、修改root密码并创建新用户
mysql> set password=password('password');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> create user 'admin'@'%' identified by '123456';
Query OK, 0 rows affected (0.00 sec)
mysql> GRANT ALL PRIVILEGES ON *.* to 'admin'@'%';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)