Centos7安装Mysql 8.0.33(傻瓜式安装)
你好呀,我的老朋友!我是老寇,欢迎来到老寇云平台!
话不多说,跟我一起安装Mysql。
# 下载Mysql
# 安装准备
注:Mysql会与MariaDB文件冲突,需要先卸载掉MariaDB
# 卸载MariaDB
# 检查是否安装MariaDB
rpm -qa|grep mariadb
# 卸载
# rpm -e --nodeps 文件名
rpm -e --nodeps mariadb-libs-5.5.35-3.el7.x86_64
# 检查是否卸载干净
rpm -qa|grep mariadb
# 检查依赖
# 是否安装libaio
rpm -qa|grep libaio
# 没有libaio则安装
yum -y install libaio
# 查看安装numactl
rpm -qa|grep numactl
# 没有则安装numactl
yum -y install numactl
# 开始安装
# 上传压缩包(略)
# 解压
# 拆分 => tar -xvf 包名
tar -xvf mysql-8.0.33-el7-x86_64.tar
# 解压 => tar -zxvf 包名
tar -zxvf mysql-8.0.33-el7-x86_64.tar.gz
# 重命名
mv mysql-8.0.33-el7-x86_64 /usr/local/mysql8
# 创建存储数据文件
mkdir -p /usr/local/mysql8/data
# 创建用户组并赋值
# 创建用户组
groupadd mysql
# 创建用户
# -r:创建系统用户
# -g:指定用户组
useradd -r -g mysql mysql
# 修改范围和权限
chown -R mysql:mysql /usr/local/mysql8
chmod -R 755 /usr/local/mysql8
# 初始化Mysql
cd /usr/local/mysql8/bin
# 初始化完成后会打印随机密码
./mysqld --initialize --user=mysql --datadir=/usr/local/mysql8/data --basedir=/usr/local/mysql8
# 配置参数
# 创建文件
touch /usr/local/mysql8/my.cnf
# 复制以下内容,根据需要修改
[client]
port = 3306
socket = /usr/local/mysql8/data/mysql.sock
default-character-set = utf8mb4
[mysql]
default-character-set = utf8mb4
[mysqld]
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_general_ci
init_connect = 'SET NAMES utf8mb4'
port = 3306
socket = /usr/local/mysql8/data/mysql.sock
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
datadir = /usr/local/mysql8/data
lower_case_table_names = 1
innodb_flush_log_at_trx_commit = 1
sync_binlog = 1
#lower_case_table_names=1
#如果要设置lower_case_table_names可以在初始化里面设置 ./mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql --lower_case_table_names=1
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
# 修改权限
chmod 777 /usr/local/mysql8/my.cnf
# 启动Mysql
# 启动
./mysqld_safe /usr/local/mysql8/my.cnf &
# 查看进程
netstat -ntlp
# 设置密码
# 登录 => 密码就是截图的随机密码
./mysql -uroot -p
# 修改密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'laokou123';
# 开放远程访问
use mysql;
update user set user.Host='%' where user.User='root';
# 刷新权限
flush privileges;
# 关闭防火墙
systemctl stop firewalld.service
# 安装完毕!!!
我是老寇,我们下次再见啦!
# 参考资料
上次更新: 11/22/2024, 4:10:36 AM