Centos8.2 安装 Mysql 5.7.26(单机)

2023-12-25 16:11:33

Mysql二进制包:? mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz

1、卸载旧环境

rpm -qa|grep mysql
rpm -qa|grep mariadb
rpm -e XXX.rpm --nodeps	# 强制卸载rpm包
rm -rf /etc/my.cnf
rm -rf /etc/mysql
rm -rf /usr/local/mysql

2、安装依赖包

yum -y install libaio
yum -y install libnuma
yum -y install libncurses.so.5 

3、创建用户

groupadd mysql
useradd -r -g mysql -s /bin/false mysql

4、创建配置文件

/etc/my.cnf

[mysqld]
bind-address=0.0.0.0
port=3306
user=mysql
basedir=/opt/mysql
datadir=/opt/mysql/data
socket=/opt/mysql/data/mysql.sock
log-error=/opt/mysql/data/mysql.err
pid-file=/opt/mysql/data//mysql.pid
character_set_server=utf8mb4
collation_server=utf8mb4_bin

[client]
port=3306
socket=/opt/mysql/data/mysql.sock
default-character-set=utf8mb4

5、解压二进制包

cd /opt
tar -zxvf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.26-linux-glibc2.12-x86_64 mysql
mkdir -p /opt/mysql/data
chown -R mysql:mysql /opt/mysql

6、初始化数据库

cd /opt/mysql
bin/mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql

7、启动数据库

cp support-files/mysql.server /etc/init.d/mysql
# 配置环境变量, /etc/profile
export PATH=$PATH:/opt/mysql/bin
# 启动数据库
service mysql start
ps -ef|grep mysql

8、测试

/opt/mysql/bin/mysql -u root -p

root初始密码在:/opt/mysql/data/mysql/mysql.err

# 修改root密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
# 查看字符集
show variables like 'chara%';
show variables like 'collation%';
# 查看数据库
show databases;
# 建库
create database test;
# 删库
drop database test;

文章来源:https://blog.csdn.net/linwenhai2018/article/details/135198872
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。