CentOS8系统安装mysql5.7

目录

  • 一、准备工作
    • 系统版本
    • mysql下载地址
    • 准备系统环境和用户组
    • 准备安装文件
  • 二、安装MYSQL
    • 配置mysql配置文件:/etc/my.cnf
    • 配置mysql.server
    • 登录权限设置:将root用户设置为任何ip可访问
  • 三、后续补充及问题解决记录
    • 问题一:ERROR 1114 (HY000) at line 10692: The table 't_user' is full

一、准备工作

系统版本

[root@wanwan ~]# cat /etc/centos-release
CentOS Linux release 8.4.2105
[root@wanwan ~]# 

mysql下载地址

mysql5.7.36官网包下载

准备系统环境和用户组

###################检查是否有mysql,若有则卸载
[root@wanwan data]# rpm -qa|grep mysql
################### 检查是否有mariadb,若有则卸载
[root@wanwan data]# rpm -qa|grep mariadb

################### 检查有无安装过mysql 用户组,没有的话创建
[root@wanwan data]# cat /etc/group | grep mysql
[root@wanwan data]# cat /etc/passwd |grep mysql
################### 创建mysql 用户组
[root@wanwan data]# groupadd mysql
[root@wanwan data]# useradd -r -g mysql mysql
[root@wanwan data]# cat /etc/group | grep mysql
mysql:x:1001:
[root@wanwan data]# cat /etc/passwd |grep mysql
mysql:x:975:1001::/home/mysql:/bin/bash
[root@wanwan data]# 

准备安装文件

################### 解压mysql安装包
[root@wanwan mysql]# tar -zxvf mysql-5.7.36-el7-x86_64.tar.gz 
################### 将mysql文件夹移动至/usr/local/mysql目录
[root@wanwan mysql-5.7.36-el7-x86_64]# mv /data/mysql/mysql-5.7.36-el7-x86_64 /usr/local/mysql

################### 更改mysql 目录下所有文件夹所属的用户组和用户,以及权限
[root@wanwan mysql-5.7.36-el7-x86_64]# chown -R mysql:mysql /usr/local/mysql
[root@wanwan mysql-5.7.36-el7-x86_64]# chmod -R 755 /usr/local/mysql
[root@wanwan mysql-5.7.36-el7-x86_64]# 

################### 创建mysql相关目录
[root@wanwan mysql-5.7.36-el7-x86_64]# mkdir -p /data/mysql/{data,logs,tmp}
[root@wanwan mysql-5.7.36-el7-x86_64]# chown -R mysql.mysql /data/mysql/

################### 创建mysql配置文件my.cnf
vim /etc/my.cnf

二、安装MYSQL

配置mysql配置文件:/etc/my.cnf

# 简单模板如下:
[client]
port = 3306
socket = /data/mysql/tmp/mysql.sock
[mysqld]
user = mysql
basedir = /usr/local/mysql 
datadir = /data/mysql/data 
port = 3306 
socket = /data/mysql/tmp/mysql.sock
pid-file = /data/mysql/tmp/mysqld.pid
tmpdir = /data/mysql/tmp 
skip_name_resolve = 1
symbolic-links=0
max_connections = 2000
group_concat_max_len = 1024000
sql_mode = NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
lower_case_table_names = 1
log_timestamps=SYSTEM
character-set-server = utf8
interactive_timeout = 1800 
wait_timeout = 1800
max_allowed_packet = 32M
binlog_cache_size = 4M
sort_buffer_size = 2M
read_buffer_size = 4M
join_buffer_size = 4M
tmp_table_size = 96M
max_heap_table_size = 96M
max_length_for_sort_data = 8096
#logs
server-id = 1003306
log-error = /data/mysql/logs/error.log
slow_query_log = 1
slow_query_log_file = /data/mysql/logs/slow.log
long_query_time = 3
log-bin = /data/mysql/logs/binlog
binlog_format = row
expire_logs_days = 15
log_bin_trust_function_creators = 1
relay-log = /data/mysql/logs/relay-bin
relay-log-recovery = 1 
relay_log_purge = 1 
#innodb 
innodb_file_per_table = 1
innodb_log_buffer_size = 16M
innodb_log_file_size = 256M
innodb_log_files_in_group = 2
innodb_io_capacity = 2000
innodb_io_capacity_max = 4000
innodb_flush_neighbors = 0
innodb_flush_method = O_DIRECT
innodb_autoinc_lock_mode = 2
innodb_read_io_threads = 8
innodb_write_io_threads = 8
innodb_buffer_pool_size = 2G

配置mysql.server

cd /usr/local/mysql/support-files
cp mysql.server /etc/init.d/mysql
################### 修改目录位置
#将/etc/init.d/mysql文件中的basedir和datadir路径按如下修改
#   basedir=/usr/local/mysql
#   datadir=/data/mysql/data
#
vim /etc/init.d/mysql

################### 注册开机启动服务
[root@wanwan support-files]# chkconfig --add mysql
[root@wanwan support-files]# chkconfig --list
################### 添加环境变量
[root@wanwan support-files]# echo "PATH=$PATH:/usr/local/mysql/bin " >> /etc/profile 
[root@wanwan support-files]# source /etc/profile
################### 初始化mysql
[root@wanwan support-files]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/data
################### 获取临时密码
[root@wanwan support-files]# more /data/mysql/logs/error.log |grep password
2022-04-19T12:04:23.659001-05:00 1 [Note] A temporary password is generated for root@localhost: 7Sc<hW2UQs&V

################### 启动mysql
[root@wanwan support-files]# service mysql start
Starting MySQL.                                            [  OK  ]

################### 登录mysql
[root@wanwan support-files]# 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.36-log

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的root用户密码为root
mysql> alter user 'root'@'localhost' identified by 'root';
Query OK, 0 rows affected (0.00 sec)
################### 刷新用户密码权限
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
################### 创建软连接
[root@wanwan bin]# ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
################### 重启mysql服务
[root@wanwan bin]# service mysql restart
################### 重新验证登录mysql用户
[root@wanwan bin]# mysql -u root -p

登录权限设置:将root用户设置为任何ip可访问

mysql> select user,host,authentication_string from user;
+---------------+-----------+-------------------------------------------+
| user          | host      | authentication_string                     |
+---------------+-----------+-------------------------------------------+
| root          | localhost | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
| mysql.session | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| mysql.sys     | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
+---------------+-----------+-------------------------------------------+
3 rows in set (0.00 sec)
mysql> update user set host = '%' where user = 'root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0
mysql> commit;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

CentOS8系统安装mysql5.7_第1张图片

三、后续补充及问题解决记录

问题一:ERROR 1114 (HY000) at line 10692: The table ‘t_user’ is full

################### 问题一:执行mysql导入时,由于表数据过多报错;
[root@wanwan mysql]# mysql -uroot -proot < full_20220420.sql 
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1114 (HY000) at line 10692: The table 't_user' is full
[root@wanwan mysql]# 

################### 解决方法,打开mysql配置文件,修改如下2个配置,然后执行service mysql restart 重启mysql服务,再重新导入
vim /etc/my.cnf
tmp_table_size = 256M
max_heap_table_size = 256M

你可能感兴趣的:(数据库,mysql安装,centos安装mysql)