MySql教程

Liunx-CentOS安装MySQL8

本文主要是介绍Liunx-CentOS安装MySQL8,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

0 卸载

0.1 卸载原有的MariaDB

查看MariaDB安装包

rpm -qa | grep mariadb

卸载MariaDB

rpm -e mariadb-libs-5.5.60-1.el7_5.x86_64 --nodeps

image
0.2 检查并卸载MySQL
查询MySQL相关的文件夹

find / -name mysql

删除
image

1 MySQL8安装包

下载地址:https://dev.mysql.com/downloads/mysql/
wget:wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.29-el7-x86_64.tar.gz

Select Operating System: 选择 Red Hat ,CentOS 是基于红帽的,Select OS Version: 选择 linux 7
image


image

上传至服务器

# 解压
tar -zxvf mysql-8.0.29-el7-x86_64.tar.gz
# 移动并重命名
mv /tmp/tools/mysql-8.0.29-el7-x86_64 mysql-8.0.29
# 进入文件夹创建mysqldb管理数据的文件夹并给权限
cd /usr/local/mysql-8.0.29/
mkdir mysqldb
chmod 777 mysqldb

2 MySQL依赖包

安装libaio

yum install libaio

3 创建MySQL组用户

# 创建组
groupadd mysql
# 创建用户,指定用户组为mysql(-s /bin/false参数指定mysql用户仅拥有所有权,而没有登录权限)
useradd -r -g mysql -s /bin/false mysql
# 将当前文件的所有者设置为MySQL,群体使用者为MySQL
chown -R mysql:mysql ./

4 添加永久性环境变量

修改配置文件/etc/profile
vim /etc/profile

在里面加入:export PATH=$PATH:MySQL地址/bin
刷新配置文件

source /etc/profile

5 修改MySQL配置文件

vim /etc/my.cnf

没有就是新建,有就全删,添加如下命令
一定要注意这些路径正常,否则无法初始化安装

[mysqld]
# 设置3306端口
port=3306
# 设置mysql的安装目录
basedir=/usr/local/mysql
# 设置mysql数据库的数据的存放目录
datadir=/usr/local/mysql/mysqldb
# 允许最大连接数
max_connections=10000
# 允许连接失败的次数。这是为了防止有人从该主机试图攻击数据库系统
max_connect_errors=10
# 服务端使用的字符集默认为UTF8
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
# 默认使用“mysql_native_password”插件认证
default_authentication_plugin=mysql_native_password
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
[client]
# 设置mysql客户端连接服务端时默认使用的端口
port=3306
default-character-set=utf8

5 安装MySQL

进入MySQL bin文件夹下

# --initialize-insecure 不生成密码
./mysqld --initialize-insecure --user=mysql --console

进入support-files启动

./mysql.server start

image

6 设置MySQL自启动

# 添加到系统进程
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
systemctl enable mysqld

# 启动
service mysql start
# 停止
service mysql stop
# 重启
service mysql restart
# 状态
service mysql status

7 修改密码

ALTER USER 'root'localhost'%' IDENTIFIED BY 'uyi@123';
update user set host='%' where user='root';
flush privileges;

8 开启端口

# 查看防火墙开放端口
firewall-cmd --list-all
# 在防火墙中将3306端口开放
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload
//--permanent为永久生效,没有此参数 服务器重启后配置失效
这篇关于Liunx-CentOS安装MySQL8的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!