天天看点

mysql centos 安装包_centos7 mysql 安装

rpm介绍

rpm 安装包:二进制包(Binary)以及源代码包(Source)两种。二进制包可以直接安装在计算机中,而源代码包将会由RPM自动编译、安装。源代码包经常以src.rpm作为后缀名

rpm包管理rpm命令管理

rpm包管理yum在线管理

mysql centos 安装包_centos7 mysql 安装
mysql centos 安装包_centos7 mysql 安装
mysql centos 安装包_centos7 mysql 安装
mysql centos 安装包_centos7 mysql 安装
mysql centos 安装包_centos7 mysql 安装
mysql centos 安装包_centos7 mysql 安装
mysql centos 安装包_centos7 mysql 安装
mysql centos 安装包_centos7 mysql 安装

rpm -ivh 包全名 安装软件包

rpm-ivh *.rpm --nodeps --force 批量安装rpm--nodeps 不校验包的依赖关系安装--force 忽略软件包及文件的冲突安装

rpm-ivh --relocate /=/opt/gaim gaim-1.3.0-1.fc4.i386.rpm //指定安装目录

rpm-ivh --test gaim-1.3.0-1.fc4.i386.rpm    //用来检查依赖关系;并不是真正的安装;

rpm-Uvh 包全名 升级软件包

rpm-e 包名 卸载软件包

rpm-qa | grep httpd  [搜索指定rpm包是否安装]--all搜索*httpd*rpm-ql 包名 列出所有文件安装目录

rpm-qf 文件名 查询一个已经安装的文件属于哪个软件包

注:文件名所在的绝对路径要指出

举例:

[[email protected] RPMS]# rpm-qf /usr/lib/libacl.la

libacl-devel-2.2.23-8rpm-qc 软件名 查看一下已安装软件的配置文件

rpm-qc mariadb-libs/etc/my.cnf/etc/my.cnf.d/mysql-clients.cnf

rpm-qd 软件名 查看一个已经安装软件的文档安装位置

rpm-qd mariadb-libs

rpm-qR 软件名 查看一下已安装软件所依赖的软件包及文件

rpm-qR mariadb-lib

mysql安装

2.使用tar命令解压

-rw-r--r-- 1 root root 545832960 Dec 19 2019 mysql-5.7.29-1.el7.x86_64.rpm-bundle.tar[[email protected] opt]#mkdirmysql

[[email protected] opt]#tar -xvf mysql-5.7.29-1.el7.x86_64.rpm-bundle.tar -C /opt/mysql

mysql-community-embedded-devel-5.7.29-1.el7.x86_64.rpm

mysql-community-test-5.7.29-1.el7.x86_64.rpm

mysql-community-embedded-5.7.29-1.el7.x86_64.rpm

mysql-community-embedded-compat-5.7.29-1.el7.x86_64.rpm

mysql-community-libs-5.7.29-1.el7.x86_64.rpm

mysql-community-client-5.7.29-1.el7.x86_64.rpm

mysql-community-server-5.7.29-1.el7.x86_64.rpm

mysql-community-devel-5.7.29-1.el7.x86_64.rpm

mysql-community-libs-compat-5.7.29-1.el7.x86_64.rpm

mysql-community-common-5.7.29-1.el7.x86_64.rpm

3.卸载centos7自带的mariadb

安装新版mysql前,需将系统自带的mariadb-lib卸载

[[email protected] opt]# rpm -qa |grepmariadb

mariadb-libs-5.5.60-1.el7_5.x86_64

[[email protected] opt]# rpm-qa |grepmariadb

mariadb-libs-5.5.60-1.el7_5.x86_64

[[email protected] opt]# rpm-e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64

4.安装mysql解压后的rpm包

为了避免出现权限问题,给mysql解压文件所在目录赋予最大权限

chmod 777 mysql

安装mysql需要的依赖

yum -y install make gcc-c++ cmake bison-devel ncurses-devel libaio libaio-devel net-tools

按顺序安装解压的rpm包

rpm -ivh --nodeps mysql-community-common-5.7.29-1.el7.x86_64.rpm

rpm -ivh --nodeps mysql/mysql-community-libs-5.7.29-1.el7.x86_64.rpm

rpm -ivh --nodeps mysql/mysql-community-libs-compat-5.7.29-1.el7.x86_64.rpm

rpm -ivh --nodeps mysql/mysql-community-client-5.7.29-1.el7.x86_64.rpm

rpm -ivh --nodeps mysql/mysql-community-server-5.7.29-1.el7.x86_64.rpm

修改配置文件

vim /etc/my.cnf 新增配置

#跳过登录验证

skip-grant-tables

#默认数据库字符集

character_set_server=utf8

#初始连接字符集UTF8

init_connect='SET NAMES utf8'

添加用户

adduser mysql

授权

chown mysql:mysql -R /var/lib/mysql

#初始化数据库

mysqld --initialize --user=mysql --datadir=/var/lib/mysql

启动服务 systemctl start mysqld

登录,输入密码时直接回车

[[email protected] log]# mysql -u root -p

Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connectionid is 2Server version:5.7.29-log MySQL Community Server (GPL)

Copyright (c)2000, 2020, Oracle and/or its affiliates. All rights reserved.

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 clearthe current input statement.

mysql>

设置密码

#设置密码

mysql> update mysql.user set authentication_string=password('123456') where user='root';

Query OK,1 row affected, 1 warning (0.00sec)

Rows matched:1 Changed: 1 Warnings: 1#立即生效

mysql>flush privileges;

Query OK,0 rows affected (0.01sec)

#开启远程登录权限, by后面的就是远程登录密码,远程登录密码可以和用户密码不一样

mysql> grant all privileges on *.* to 'root'@'%' identified by '123456'with grant option;

Query OK,0 rows affected, 1 warning (0.00 sec)

设置密码策略(该步骤可以跳过)

如果想要设置简单一点的密码就要设置密码策略,否则设置简单的密码会出错

SHOW VARIABLES LIKE 'validate_password%'; #查看密码策略

mysql centos 安装包_centos7 mysql 安装

1)、validate_password_length  固定密码的总长度;

2)、validate_password_dictionary_file 指定密码验证的文件路径;

3)、validate_password_mixed_case_count  整个密码中至少要包含大/小写字母的总个数;

4)、validate_password_number_count  整个密码中至少要包含阿拉伯数字的个数;

5)、validate_password_policy 指定密码的强度验证等级,默认为 MEDIUM;

设置密码的验证强度等级,设置 validate_password_policy 的全局参数为 LOW

set global validate_password_policy=LOW;

mysql centos 安装包_centos7 mysql 安装

只要设置密码的长度小于 3 ,都将自动设值为 4

set global validate_password_length=4;

mysql centos 安装包_centos7 mysql 安装

停止服务:systemctl stop mysqld,编辑my.cnf配置文件将:skip-grant-tables这一行注释掉

重启mysql : systemctl start mysqld

执行命令报错解决方式如下:

MySQL版本5.7.6版本以前用户可以使用如下命令:

mysql> SET PASSWORD = PASSWORD('123456');

MySQL版本5.7.6版本开始的用户可以使用如下命令:

mysql>ALTER USER USER() IDENTIFIED BY '123456';

mysql>show databases;

ERROR1820(HY000): You must reset your password using ALTER USER statement before executing this statement.

mysql> set password=password('123456');

Query OK,0 rows affected, 1 warning (0.00sec)

mysql>show databases;+--------------------+

| Database |

+--------------------+

| information_schema |

| mysql |

| performance_schema |

| sys |

+--------------------+

4 rows in set (0.00 sec)

上面问题原因分析:

MySQL版本5.6.6版本起,添加了password_expired功能,它允许设置用户的过期时间。这个特性已经添加到mysql.user数据表,但是它的默认值是”N”,可以使用ALTER USER语句来修改这个值。

输入以下命令,将账号密码强制到期:

mysql>ALTER USER 'xiaoming'@'localhost' PASSWORD EXPIRE;

此时,用户可以登录到MYSQL服务器,但是在用户为设置新密码之前,不能运行任何命令,就会得到上图的报错,修改密码即可正常运行账户权限内的所有命令。由于此版本密码过期天数无法通过命令来实现,所以DBA可以通过cron定时器任务来设置MySQL用户的密码过期时间。

MySQL 5.7.4版开始,用户的密码过期时间这个特性得以改进,可以通过一个全局变量default_password_lifetime来设置密码过期的策略,此全局变量可以设置一个全局的自动密码过期策略。可以在MySQL的my.cnf配置文件中设置一个默认值,这会使得所有MySQL用户的密码过期时间都为120天,MySQL会从启动时开始计算时间。my.cnf配置如下:

[mysqld]

default_password_lifetime=120

如果要设置密码永不过期,my.cnf配置如下:

[mysqld]

default_password_lifetime=0

如果要为每个具体的用户账户设置单独的特定值,可以使用以下命令完成(注意:此命令会覆盖全局策略),单位是“天”,命令如下:

ALTER USER ‘xiaoming’@‘localhost'PASSWORD EXPIRE INTERVAL 250 DAY;

如果让用户恢复默认策略,命令如下:

ALTER USER 'xiaoming'@'localhost' PASSWORD EXPIRE DEFAULT;

个别使用者为了后期麻烦,会将密码过期功能禁用,命令如下:

ALTER USER 'testuser'@'localhost' PASSWORD EXPIRE NEVER;

开放3306端口

firewall-cmd --zone=public --add-port=3306/tcp --permanent

--zone #作用域

--add-port=80/tcp #添加端口,格式为:端口/通讯协议

--permanent #永久生效,没有此参数重启后失效

重启防火墙firewall-cmd --reload

设置开机自启动 : systemctl enable mysqld

查看服务状态: systemctl status mysqld

常用命令:

show databases;查看所有的数据库

status 查看mysql数据库的运行状态

show tables 查看数据库中的表

desc table_name;查看表结构

show full processlist;#查询数据库连接

show status like'%Max_used_connections%';

show status like'%Threads_connected%';#当前连接数

show status like'%table_lock%';#表锁定

show status like'innodb_row_lock%';#行锁定

show status like'%qcache%'; #查询缓存情况

show variables like"%query_cache%";

SHOW STATUS LIKE'Qcache%';

show variables like"%binlog%";

show status like'Aborted_clients';#由于客户没有正确关闭连接已经死掉,已经放弃的连接数量

show variables like'%max_connections%';//查看最大连接数量

show variables like '%timeout%';#查看超时时间

show variables like'log_%'; #查看日志是否启动

shell脚本一键安装:

#! /bin/bashtar xf mysql-5.7.26-1.el7.x86_64.rpm-bundle.tar -C /opt/mysql/

yum -y install make gcc-c++ cmake bison-devel ncurses-devel libaio libaio-devel net-tools

rpm-qa | grepmariadbyum -y remove mariadb-libs

rpm-ivh --nodeps mysql/mysql-community-common-5.7.26-1.el7.x86_64.rpm

rpm-ivh --nodeps mysql/mysql-community-libs-5.7.26-1.el7.x86_64.rpm

rpm-ivh --nodeps mysql/mysql-community-libs-compat-5.7.26-1.el7.x86_64.rpm

rpm-ivh --nodeps mysql/mysql-community-client-5.7.26-1.el7.x86_64.rpm

rpm-ivh --nodeps mysql/mysql-community-server-5.7.26-1.el7.x86_64.rpm

systemctl start mysqld

systemctl enable mysqld

systemctl status mysqld

#! /bin/bash

rpm-Uvh mysql/*.rpm --nodeps --force

service mysqld start

sleep 10

result=`grep "new password" /var/log/mysqld.log |awk '{print $NF}'`

p1="`echo $result |awk '{print $NF}'`"

echo "password:$p1"

if [ "$p1" == "" ]; then

result=`grep "temporary password" /var/log/mysqld.log |awk '{print $NF}'`

p1="`echo $result |awk '{print $NF}'`"

fi

echo "password:$p1"

mysql -uroot -p$p1 --connect-expired-password -D mysql <

SET GLOBAL innodb_flush_log_at_trx_commit =0;

set global validate_password_policy=0;

set global validate_password_length=1;

set global time_zone = '+8:00';

create database if not exists \`test\` default character set utf8 default collate utf8_general_ci;

EOF

echo "new password 123456" >> /var/log/mysqld.log

sleep 10

mysql -uroot -p$p1 --connect-expired-password -D mysql <

alter user 'root'@'localhost' identified by '123456';

update mysql.user set authentication_string=password('123456') where user='root' and host='localhost';

GRANT ALL ON *.* TO 'root'@'%' IDENTIFIED BY '123456';

GRANT ALL ON *.* TO 'root'@'127.0.0.1' IDENTIFIED BY '123456';

flush privileges;

use test;

source /opt/mysql/test.sql;

EOF

sleep 10