Centos7中安装MySQL5.7!! 超级详细,这篇完全足够!!!!(细节一定要到位!笔记)

开始准备

进入命令行
[zoro@localhost ~]$ 
更改权限
[zoro@localhost ~]$ su root
密码:
输入密码进来 管理者命令行
[root@localhost zoro]# 
切换目录
[root@localhost zoro]# cd /root
[root@localhost ~]# 
下载安装包MySQL5.7 Linux版本
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
打开目录有这么个包
[root@localhost ~]# ls
mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
查看并删除原始数据库
[root@localhost ~]# rpm -qa |grep mariadb
mariadb-5.5.56-2.el7.x86_64
mariadb-libs-5.5.56-2.el7.x86_64
mariadb-server-5.5.56-2.el7.x86_64
[root@localhost ~]# rpm -e --nodeps mariadb-5.5.56-2.el7.x86_64
[root@localhost ~]# rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64
[root@localhost ~]# rpm -e --nodeps mariadb-server-5.5.56-2.el7.x86_64
[root@localhost ~]# 
[root@localhost ~]# rpm -qa |grep mariadb
[root@localhost ~]# 

小Tips 它来了

//linux 中复制粘贴会很麻烦吧,鼠标右键选复制粘贴
//但是我带来了一个快捷键
Ctrl+insert  复制选中的部分
Shift+insert 粘贴选中的部分
安装依赖
[root@localhost ~]# rpm -qa |grep libaio
[root@localhost ~]# 
[root@localhost ~]# yum -y install libaio
// 安装好后查看
[root@localhost ~]# rpm -qa |grep libaio
libaio-0.3.109-13.el7.x86_64

[root@localhost ~]# rpm -qa | grep numactl
[root@localhost ~]#
[root@localhost ~]# yum -y install numactl
//  安装好后查看
[root@localhost ~]# rpm -qa | grep numactl
numactl-libs-2.0.9-7.el7.x86_64

准备工作完毕!!!

开始

解压准备好的安装包
[root@localhost ~]# tar -zxvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz 
名字更改为mysql 并且修改位置
[root@localhost ~]# mv mysql-5.7.24-linux-glibc2.12-x86_64  /usr/local/mysql
[root@localhost ~]# cd /usr/local
创建mysql组,创建mysql用户,修改权限
[root@localhost local]# groupadd mysql
[root@localhost local]# useradd -g mysql mysql
//修改文件用户
[root@localhost local]# chown -R mysql mysql/
//修改文件用户组
[root@localhost local]# chgrp -R mysql mysql/
[root@localhost local]# ll
总用量 0
drwxr-xr-x. 9 mysql mysql 129 321 19:23 mysql
mysql 文件夹下创建data 目录
[root@localhost local]# mkdir /usr/local/mysql/data
编译安装并初始化mysql,务必记住初始化输出日志末尾的密码(数据库管理员临时密码)
[root@localhost bin]#  ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --lc_messages_dir=/usr/local/mysql/share --lc_messages=en_US
2024-03-21T12:07:05.707693Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2024-03-21T12:07:05.892450Z 0 [Warning] InnoDB: New log files created, LSN=45790
2024-03-21T12:07:05.921089Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2024-03-21T12:07:05.978535Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 88f48a25-e77b-11ee-a66d-000c29829cfb.
2024-03-21T12:07:05.979261Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2024-03-21T12:07:05.980080Z 1 [Note] A temporary password is generated for root@localhost: 复制密码
修改配置文件
[root@localhost local]# vi /etc/my.cnf 

小Tips

/** 会进入一个空文件,点检insert按钮开始编辑
* 	Shift+insert 粘贴
* 	点击esc,退出编辑
* 	Shift + : 按钮一起点击
* 	出现  : 
* 	然后wq保存退出
*/
# 服务端使⽤的字符集默认为8⽐特编码的latin1字符集
character-set-server=utf8
:wq //这样

复制下面的

[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
socket=/var/lib/mysql/mysql.sock
[mysqld]
skip-name-resolve
#设置3306端⼝
port = 3306
socket=/var/lib/mysql/mysql.sock
# 设置mysql的安装⽬录
basedir=/usr/local/mysql
# 设置mysql数据库的数据的存放⽬录
datadir=/usr/local/mysql/data
# 允许最⼤连接数
max_connections=200
# 服务端使⽤的字符集默认为8⽐特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使⽤的默认存储引擎
default-storage-engine=INNODB
lower_case_table_names=1
max_allowed_packet=16M
[root@localhost mysql]# cp ./support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql]# 

复制启动脚本到资源⽬录

[root@localhost mysql]# vi /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data

# Default value, in seconds, afterwhich the script should timeout waiting
# for server start.
# Value here is overriden by value in my.cnf.
# 0 means don't wait at all
# Negative numbers mean to wait indefinitely
service_startup_timeout=900

# Lock directory for RedHat / SuSE.
lockdir='/var/lock/subsys'
lock_file_path="$lockdir/mysql"

:wq

:wq 保存退出
小Tips

/*  / 斜杠 后面写自己找的关键字可以找到,其他的你可以网上查找一下吧,好像能找最附近的,呵呵哈哈哈
\basedir
设置为可执行状态
//授权为可执行状态
//⾸先增加 mysqld 服务控制脚本执⾏权限:
[root@localhost mysql]# chmod +x /etc/init.d/mysqld
//开机启动
//同时将 mysqld 服务加⼊到系统服务:
[root@localhost mysql]# chkconfig --add mysqld
//最后检查 mysqld 服务是否已经⽣效即可:
[root@localhost mysql]# chkconfig --list mysqld

注:该输出结果只显示 SysV 服务,并不包含
原生 systemd 服务。SysV 配置数据
可能被原生 systemd 配置覆盖。 

      要列出 systemd 服务,请执行 'systemctl list-unit-files'。
      查看在具体 target 启用的服务请执行
      'systemctl list-dependencies [target]'。

mysqld         	0:1:2:3:4:5:6:[root@localhost mysql]# 

启动mysql

[root@localhost mysql]# service mysqld start
Starting MySQL.                                            [  确定  ]
[root@localhost mysql]# 

配置环境变量

[root@localhost ~]# vi /etc/profile
//添加下面一行wq保存退出
export PATH=$PATH:/usr/local/mysql/bin
:wq
[root@localhost ~]# 
//
[root@localhost ~]# source /etc/profile
登录mysql 密码是初始化中的最后localhost:后面的密码
[root@localhost mysql]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.24

Copyright (c) 2000, 2018, 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 clear the current input statement.

mysql> 
修改密码
mysql> set password for root@localhost = password('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)

开放远程连接

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

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

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

但是还是有问题
windows 上的Navicat是连接不上的
在这里插入图片描述

这个问题该怎么解决呢?

打开远程访问权限,修改完退出mysql ,quit 命令

BY 后面是数据库密码

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY '123456' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql>quit
Bye
防火墙开放mysql使用的3306端口
[root@localhost mysql]# cd /root
[root@localhost ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
success
重启防火墙
[root@localhost ~]# systemctl restart firewalld.service
[root@localhost ~]# 
查看防火墙开放的端口
[root@localhost ~]# firewall-cmd --list-ports
3306/tcp

这样数据库连上了 大功靠成!!!!

在这里插入图片描述

  • 8
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值