Linux安装mysql

安装包准备

#查看mysql是否安装,如果安装了,卸载mysql
hive] rpm -qa|grep mysql  #如果出现下面的提示,就说明系统已经有了mysql,要卸载 mysql-libs-5.1.73-7.el6.x86_64
# 卸载mysql
hive] rpm -e --nodeps mysql-libs-5.1.73-7.el6.x86_64
安装MySql服务器

mysql安装的步骤介绍

# 1. 下载mysql服务端(先从本地上传服务端和客户端到服务器,尽量使用root用户操作)
# 如果本地没有 可以下面命令在线下载5.7版本
soft]# wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

# 2. 通过命令进行安装:
soft]# rpm -ivh  mysql57-community-release-el7-11.noarch.rpm


# 通过下面命令可以查看是否安装
soft]# yum repolist all| grep mysql
mysql-cluster-7.5-community/x86_64 MySQL Cluster 7.5 Community   disabled
mysql-cluster-7.5-community-source MySQL Cluster 7.5 Community - disabled
mysql-cluster-7.6-community/x86_64 MySQL Cluster 7.6 Community   disabled
mysql-cluster-7.6-community-source MySQL Cluster 7.6 Community - disabled
mysql-connectors-community/x86_64  MySQL Connectors Community    enabled:    141
mysql-connectors-community-source  MySQL Connectors Community -  disabled
mysql-tools-community/x86_64       MySQL Tools Community         enabled:    105
mysql-tools-community-source       MySQL Tools Community - Sourc disabled
mysql-tools-preview/x86_64         MySQL Tools Preview           disabled
mysql-tools-preview-source         MySQL Tools Preview - Source  disabled
mysql55-community/x86_64           MySQL 5.5 Community Server    disabled
mysql55-community-source           MySQL 5.5 Community Server -  disabled
mysql56-community/x86_64           MySQL 5.6 Community Server    disabled
mysql56-community-source           MySQL 5.6 Community Server -  disabled
mysql57-community/x86_64           MySQL 5.7 Community Server    enabled:    404
mysql57-community-source           MySQL 5.7 Community Server -  disabled
mysql80-community/x86_64           MySQL 8.0 Community Server    disabled
mysql80-community-source           MySQL 8.0 Community Server -  disabled
# 通过上面可以看到mysql5.7 是enable状态

# 3. 通过yum开始mysql安装
soft]# yum install -y mysql-community-server

# 4. 启动mysql服务
# 启动数据库
soft]# systemctl start mysqld   
# 设置开机自启数据库
soft]# systemctl enable mysqld  

# 5. 查看产生的随机密码,运行命令后最后显示的xuzmpubKv0(f即为密码
soft]# grep 'password' /var/log/mysqld.log
2020-04-14T19:20:47.261622Z 1 [Note] A temporary password is generated for root@localhost: xuzmpubKv0(f

# 6. 用上述密码登录数据库
soft] mysql -u root -p

# 7. 修改密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Root567!';

注意:登录成功后,要降低密码策略机制,改为low,也可以将密码长度6.

set global validate_password_policy=low;
set global validate_password_length=6;

查看密码策略
show variables like '%validate_password%';

远程授权:如果想要远程连接mysql,需要进行远程授权操作(注意,一定要关闭防火墙)

grant all privileges on *.* to root@"%" identified by '远程密码' with grant option;
上一篇:centos安装mysql


下一篇:Linux中MySQL的安装以及卸载