CentOS7.x安装mysql-5.7.23标准化教程

本文详细介绍了如何在Linux系统中手动安装、配置MySQL5.7,包括卸载旧版本、安装依赖、创建用户组、设置my.cnf配置、初始化数据库、修改用户密码以及授权等步骤。
摘要由CSDN通过智能技术生成

一、前期准备

// rpm包安装方式卸载
查包名:

rpm -qa|grep -i mysql

删除命令:rpm -e –nodeps 包名
 
// yum安装方式下载
1. 查看已安装的mysql

rpm -qa | grep -i mysql

2. 卸载mysql (命令中mysql版本后为上一步查询出来的,自行修改)

yum remove mysql-community-server-8.0.13-1.el7.x86_64

查看mysql的其它依赖:rpm -qa | grep -i mysql
 
// 卸载依赖

yum remove mysql-libs
yum remove mysql-server
yum remove perl-DBD-MySQL
yum remove mysql

// 查找mysql残留包,有则删除,没有则忽略

find / -name mysql

3. 安装相关依赖

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

4. 创建用户和用户组

groupadd mysql
useradd -s /sbin/nologin -g mysql -M mysql

二、下载二进制安装包并解压

cd /usr/local/
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
tar -zxvf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.23-linux-glibc2.12-x86_64 mysql

三、mysql文件夹授权,创建相关文件夹并授权

chown -R mysql.mysql /usr/local/mysql/
mkdir -p /data/mysql/{data,logs,tmp}
chown -R mysql.mysql /data/mysql/

四、创建mysql配置文件my.cnf并添加内容

vi /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

注:配置文件中有一句:“skip_name_resolve = 1”,这行配置可能会导致数据库安装完毕后,linux命令可以正常访问并使用数据库,但是部署的web项目无法正常连接到数据库!固,被注释掉了。直接删除改行配置也可以。

五、配置mysql.server

cd /usr/local/mysql/support-files
cp mysql.server /etc/init.d/mysql
vi /etc/init.d/mysql

修改目录位置 (找到相关位置进行修改)

basedir=/usr/local/mysql
datadir=/data/mysql/data

注册开机启动

chkconfig --add mysql
chkconfig --list

六、初始化

/usr/local/mysql/bin/mysqld  --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/data

获取mysql登录临时密码

more /data/mysql/logs/error.log |grep password

七、启动mysql并修改用户密码

启动

service mysql start

修改密码

mysql -uroot -p

如上述命令执行报:-bash: mysql: command not found,见此文第十条

输入刚才获取的临时密码,回车。输入新密码,回车。再次输入新密码,回车。

到此,密码修改完成!

八、mysql用户授权

use mysql;
grant all privileges on *.* to '数据库用户名'@'%' identified by '数据库密码' with grant option;
flush privileges;

如连接数据库报:-bash: mysql: command not found,见此文第十条

九、重启数据库

service mysql restart

十、建立mysql命令链接

ln -s /usr/local/mysql/bin/mysql /usr/bin

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值