【Linux】CentOS7安装mysql5.7

馋奶兔 提交于 2021-02-14 11:39:59

官网下载地址

https://dev.mysql.com/downloads/file/?id=471503

​ 本文所用MySQL版本为5.7.19;

上传包

​ 将mysql-5.7.19-1.el7.x86_64.rpm-bundle.tar 安装包上传到/opt/soft目录(此目录可以自定义),采用rz命令;

[root@bigdata112 conf]# rz

​ 若不存在rz命令,可以用yum进行安装(如下代码),安装完成再执行rz 上传包命令;

[root@bigdata112 ~]# yum install lrzsz

检测是否已有mysql

[root@bigdata112 ~]# rpm -qa | grep mysql

检测是否已有Mariadb

[root@bigdata112 mysql-5.7.19]# rpm -qa | grep mariadb
mariadb-libs-5.5.44-2.el7.centos.x86_64

​ 若存在则卸载;

[root@bigdata112 mysql-5.7.19]# rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64

解压包

​ 将mysql压缩包解压到/op/module/mysql-5.7.19目录,若没有则新建一个目录;

​ 因为我们下载的是.tar压缩包,所以命令为:tar -vxf

[root@bigdata112 ~]# tar -vxf /opt/soft/mysql-5.7.19-1.el7.x86_64.rpm-bundle.tar -C /opt/module/mysql-5.7.19/

安装mysql

​ 切换到/opt/module/mysql-5.7.19/目录,依次执行以下命令:

​ 安装server

[root@bigdata112 mysql-5.7.19]# rpm -ivh --nodeps mysql-community-server-5.7.19-1.el7.x86_64.rpm

​ 安装client

[root@bigdata112 mysql-5.7.19]# rpm -ivh --nodeps mysql-community-client-5.7.19-1.el7.x86_64.rpm

​ 安装common

[root@bigdata112 mysql-5.7.19]# rpm -ivh mysql-community-common-5.7.19-1.el7.x86_64.rpm

​ 安装libs

[root@bigdata112 mysql-5.7.19]# rpm -ivh mysql-community-libs-5.7.19-1.el7.x86_64.rpm

​ 安装libs-compat

[root@bigdata112 mysql-5.7.19]# rpm -ivh mysql-community-libs-compat-5.7.19-1.el7.x86_64.rpm

启动mysql服务

[root@bigdata112 mysql-5.7.19]# systemctl start mysqld

查看mysql服务状态

[root@bigdata112 mysql-5.7.19]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since 日 2019-09-08 21:36:35 CST; 1h 34min ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 3474 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 3401 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 3478 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─3478 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

9月 08 21:36:32 bigdata112 systemd[1]: Starting MySQL Server...
9月 08 21:36:35 bigdata112 systemd[1]: Started MySQL Server.

查看默认生成的root密码

[root@bigdata112 mysql-5.7.19]# cat /var/log/mysqld.log | grep password
2019-09-08T15:15:25.399553Z 1 [Note] A temporary password is generated for root@localhost: m5D_fhi6%y61

登录mysql

[root@bigdata112 mysql-5.7.19]# mysql -uroot -p'm5D_fhi6%y61'

修改mysql密码规则

  1. 密码强度检查等级,0/LOW、1/MEDIUM、2/STRONG

    mysql> set global validate_password_policy=0;
    
  2. 密码至少要包含的小写字母个数和大写字母个数

    mysql> set global validate_password_mixed_case_count=0;
    
  3. 密码至少要包含的数字个数

    mysql> set global validate_password_number_count=3;
    
  4. 密码至少要包含的特殊字符数

    mysql> set global validate_password_special_char_count=0;
    
  5. 密码最小长度,参数默认为8

    mysql> set global validate_password_length=3;
    

修改密码

mysql> alter user root@localhost identified by 'root1234';
mysql> flush privileges;

测试mysql

​ 显示数据库列表

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

​ 显示刚才设置的密码规则

mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+-------+
| Variable_name                        | Value |
+--------------------------------------+-------+
| validate_password_check_user_name    | OFF   |
| validate_password_dictionary_file    |       |
| validate_password_length             | 3     |
| validate_password_mixed_case_count   | 0     |
| validate_password_number_count       | 3     |
| validate_password_policy             | LOW   |
| validate_password_special_char_count | 0     |
+--------------------------------------+-------+
7 rows in set (0.00 sec)

修改远程登录权限

​ 查询user表内用户的登录权限

mysql> select host,user from mysql.user;
+-----------+---------------+
| host      | user          |
+-----------+---------------+
| localhost | mysql.session |
| localhost | mysql.sys     |
| localhost | root          |
+-----------+---------------+
3 rows in set (0.00 sec)

​ 修改root登录权限为所有%

mysql> update mysql.user set host = '%' where user = 'root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

​ 刷新缓存

mysql> flush privileges;

测试远程登录权限

​ 利用navicat客户端建立连接,测试是否成功;

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!