rpm -qa|grep mariadb
rpm -e --nodeps mariadb-libs
yum install libaio perl net-tools
wget https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz
tar -xvf mysql
rpm安装
rpm -qa | grep mysql rpm -e --nodeps {-file-name} rpm -ivh mysql-community-common-5.7.22-1.el7.x86_64.rpm rpm -ivh mysql-community-libs-5.7.22-1.el7.x86_64.rpm rpm -ivh mysql-community-client-5.7.22-1.el7.x86_64.rpm rpm -ivh mysql-community-server-5.7.22-1.el7.x86_64.rpm ps -ef|grep mysql grep 'temporary password' /var/log/mysqld.log set global validate_password_policy=0; set global validate_password_length=1; set password for root@localhost=password('root'); set password = password('root') grant all privileges on *.* to root@'%' identified by 'root'; flush privileges;
修改data目录,开启binlog、slowlog
mv /var/lib/mysql /data
mkdir /data/mysql/log
chown mysql:mysql /data/mysql/log
chcon -R -u system_u /data/mysql/log
chcon -Rv -u system_u -t mysqld_db_t /data/mysql
semanage fcontext -a -t mysqld_db_t "/data/mysql(/.*)?"
restorecon -Rv /data/mysql
semanage port -a -t mysqld_port_t -p tcp port_number
# grep "/data/mysql" /etc/selinux/targeted/contexts/files/file_contexts.local
/data/mysql(/.*)? system_u:object_r:mysqld_db_t:s0
/data/mysql system_u:object_r:mysqld_db_t:s0
fixfiles restore
vim /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[client]
port = 3306
default-character-set = utf8mb4
socket=/data/mysql/mysql.sock
[mysql]
port = 3306
default-character-set = utf8mb4
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/data/mysql
socket=/data/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
############################
## 关闭DNS反向解析
############################
skip-name-resolve
max_allowed_packet = 512M
innodb_log_file_size = 2G
############################
### character set
############################
character-set-server=utf8mb4
collation-server=utf8mb4_bin
##########################
## binlog
###########################
server-id = 6508
###设置日志三种格式:STATEMENT、ROW、MIXED 。
binlog_format = mixed
###设置日志路径,注意路经需要mysql用户有权限写
log-bin = /data/mysql/logs/mysql-bin.log
###设置binlog清理时间
expire_logs_days = 7
###binlog每个日志文件大小
max_binlog_size = 100m
###binlog缓存大小
binlog_cache_size = 4m
###最大binlog缓存大小
max_binlog_cache_size = 512m
##############################
##slowlog
##############################
###设置日志开启
slow_query_log =1
###设置日志路径
slow_query_log_file=/data/mysql/logs/mysql-slow.log
###设置超过时长日志记录
long_query_time = 2
- 查看用户:cut -d : -f 1 /etc/passwd
- 查看用户组:cut -d : -f 1 /etc/group
- 删除xiaoluo这个用户:userdel -r xiaoluo
要安装和使用 MySQL 二进制分发,命令序列如下所示:
shell> groupadd mysql shell> useradd -r -g mysql -s /bin/false mysql shell> cd /usr/local shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz shell> ln -s full-path-to-mysql-VERSION-OS mysql shell> cd mysql shell> mkdir mysql-files shell> chown mysql:mysql mysql-files shell> chmod 750 mysql-files shell> bin/mysqld --initialize --user=mysql shell> bin/mysql_ssl_rsa_setup shell> bin/mysqld_safe --user=mysql & # Next command is optional shell> cp support-files/mysql.server /etc/init.d/mysql.server
此过程假定您具有(管理员)对系统的访问权限。或者,您可以使用 sudo (Linux)或pfexec (Solaris)命令为每个命令添加前缀。root
该目录提供了一个方便的位置,用作系统变量的值,从而将导入和导出操作限制在特定目录。请参阅第 5.1.7 节"服务器系统变量"。mysql-files
secure_file_priv
接下来是上述用于安装二进制分发的说明的更多详细信息版本。
创建 mysql 用户和组
如果您的系统还没有用于运行mysqld 的用户和组,则可能需要创建它们。以下命令添加组和用户。您可能希望调用用户并分组其他内容,而不是 。如果是,请用以下说明中替换相应的名称。在 Unix/Linux的不同版本中,使用radd和 groupad 的语法可能略有不同,或者它们可能具有不同的名称,如adduser 和 addgroup。 mysql
mysql
mysql
shell> groupadd mysql shell> useradd -r -g mysql -s /bin/false mysql
由于用户仅出于所有权目的,而不是出于登录目的,因此 useradd命令使用 和 选项创建对服务器主机没有登录权限的用户。如果您的使用rad 不支持这些选项,请忽略它们。-r
-s /bin/false
获取并解包分布
选取要解压缩分发的目录,并更改其位置。此处的示例解压缩下的分配。因此,这些说明假定您有权在 中创建文件和目录。如果该目录受到保护,则必须执行安装为 。/usr/local
/usr/local
root
shell> cd /usr/local
使用第2.1.3 节"如何获取 MySQL"中的说明获取分发文件。对于给定版本,所有平台的二进制分发都是从相同的 MySQL 源分发构建的。
解压缩创建安装目录的分发。 tar可以解压缩和解压缩分布,如果它有选项支持:z
shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz
tar命令创建一个名为 的目录。mysql-
VERSION
-OS
若要从压缩 tar 文件二进制分发安装MySQL,系统必须具有 GNU 来解压缩分发,并具有合理的tar解压缩器才能解压缩。如果您的tar程序支持该选项,它可以解压缩和解压缩文件。gunzip
z
众所周知,GNU焦油工作。某些操作系统提供的标准 tar 无法解压缩 MySQL 发行版中的长文件名。您应该下载并安装 GNU tar,或者如果可用,请使用预安装的 GNU tar 版本。通常,这可作为gnutar 、gtar或 GNU 或自由软件目录中的焦油提供,例如 或 。GNU焦油可从http://www.gnu.org/software/tar/。/usr/sfw/bin
/usr/local/bin
如果您的tar没有选项支持,请使用gunzip 解压缩分发,然后使用tar解包。将前面的tar命令替换为以下替代命令以解压缩并提取分布:z
shell> gunzip < /path/to/mysql-VERSION-OS.tar.gz | tar xvf -
接下来,创建一个符号链接到 tar 创建的安装目录:
shell> ln -s full-path-to-mysql-VERSION-OS mysql
该命令创建指向安装目录的符号链接。这使您可以更轻松地将其引用为 。若要避免在使用 MySQL 时始终键入客户端程序的路径名称,可以将目录添加到变量中:ln
/usr/local/mysql
/usr/local/mysql/bin
PATH
shell> export PATH=$PATH:/usr/local/mysql/bin
执行安装后设置
安装过程的其余部分包括设置分发所有权和访问权限、初始化数据目录、启动 MySQL 服务器以及设置配置文件