Centos7 安装Mysql(RPM)

米斯特程序猿 2021年09月10日 432次浏览

下载RPM包

官方下载如下图,为减少各种问题,我这里选择了第一个RPM Bundle 完整包

image.png

检查机器上是否已经安装了其它版本的MYSQL,如果执行命令没有任何提示,说明机器比较干净,如果有安装其它版本的请参考卸载旧版本MYSQL

# rpm -qa | grep mysql

检查是否安装了 libaio 包

  • 检测 libaio 什么都不显示说明没有 libaio 包
# rpm -qa|grep libaio
  • 安装 libaio 包
# yum -y install libaio

使用 tar -xvf [下载的mysql] 包命令解压出来安装包

image.png

依次安装即可(注意版本,我这里是5.7.34)

# rpm -ivh mysql-community-common-5.7.34-1.el7.x86_64.rpm
# rpm -ivh mysql-community-libs-5.7.34-1.el7.x86_64.rpm
# rpm -ivh mysql-community-client-5.7.34-1.el7.x86_64.rpm
# rpm -ivh mysql-community-server-5.7.34-1.el7.x86_64.rpm

安装时出现问题解决办法

  • mariadb 冲突
# rpm -ivh mysql-community-libs-5.7.34-1.el7.x86_64.rpm
warning: mysql-community-libs-5.7.34-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
	mysql-community-common(x86-64) >= 5.7.9 is needed by mysql-community-libs-5.7.34-1.el7.x86_64
	mariadb-libs is obsoleted by mysql-community-libs-5.7.34-1.el7.x86_64
  • 卸载 mariadb ,卸载后需要重新依次安装各个 rpm
# rpm -qa | grep mariadb
mariadb-libs-5.5.60-1.el7_5.x86_64
# rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64

启动mysql,启动后会创建root的初始密码

# systemctl start mysqld

修改初始密码

  • 使用命令查找密码
# grep 'temporary password' /var/log/mysqld.log
# 2021-09-10T02:54:46.731675Z 1 [Note] A temporary password is generated for root@localhost: 这里是初始密码
  • 登录mysql
# mysql -uroot -p
Enter password: 输入查到的密码
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.34

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
  • 修改密码
mysql> set password for root@localhost=password('1234567890');
Query OK, 0 rows affected, 1 warning (0.00 sec) 
  • 修改权限,可以远程访问
mysql> grant all privileges on *.* to root@'%' identified by '1234567890';
mysql> flush privileges;
  • 修改权限,可以创建用户
mysql> update mysql.user set Grant_priv='Y' where user='root' and host ='%';
mysql> flush privileges;