从https://dev.mysql.com/downloads/mysql/下载mysql-8.0.29-1.el7.x86_64.rpm-bundle.tar
建立目录
[root@vm home]# mkdir mysql
复制上传tar文件到mysql目录
检查原有的mariadb并删除
[root@vm home]# rpm -qa|grep mariadb
mariadb-libs-5.5.52-1.el7.x86_64
[root@vm home]# rpm -e --nodeps mariadb-libs复制
5.解压缩安装包
[root@vm mysql]# tar -xvf mysql-8.0.29-1.el7.x86_64.rpm-bundle.tar
mysql-community-client-8.0.29-1.el7.x86_64.rpm
mysql-community-client-plugins-8.0.29-1.el7.x86_64.rpm
mysql-community-common-8.0.29-1.el7.x86_64.rpm
mysql-community-debuginfo-8.0.29-1.el7.x86_64.rpm
mysql-community-devel-8.0.29-1.el7.x86_64.rpm
mysql-community-embedded-compat-8.0.29-1.el7.x86_64.rpm
mysql-community-icu-data-files-8.0.29-1.el7.x86_64.rpm
mysql-community-libs-8.0.29-1.el7.x86_64.rpm
mysql-community-libs-compat-8.0.29-1.el7.x86_64.rpm
mysql-community-server-8.0.29-1.el7.x86_64.rpm
mysql-community-server-debug-8.0.29-1.el7.x86_64.rpm
mysql-community-test-8.0.29-1.el7.x86_64.rpm复制
6.依次安装rpm
[root@vm mysql]# rpm -ivh mysql-community-common-8.0.29-1.el7.x86_64.rpm
[root@vm mysql]# rpm -ivh mysql-community-client-plugins-8.0.29-1.el7.x86_64.rpm
[root@vm mysql]# rpm -ivh mysql-community-libs-8.0.29-1.el7.x86_64.rpm
[root@vm mysql]# rpm -ivh mysql-community-client-8.0.29-1.el7.x86_64.rpm
[root@vm mysql]# rpm -ivh mysql-community-icu-data-files-8.0.29-1.el7.x86_64.rpm
[root@vm mysql]# rpm -ivh mysql-community-server-8.0.29-1.el7.x86_64.rpm复制
7.停止mysql服务
[root@vm mysql]# systemctl stop mysqld
[root@vm mysql]# systemctl status mysqld复制
8.初始化mysql
[root@vm mysql]# mysqld --initialize --console复制
9.目录授权
[root@vm lib]# chown -R mysql:mysql var/lib/mysql/复制
10.查看mysql临时密码,此处临时密码是31rSi;4wgt(h
[root@vm lib]# cat var/log/mysqld.log
2022-06-30T06:13:31.333655Z 0 [System] [MY-013169] [Server] usr/sbin/mysqld (mysqld 8.0.29) initializing of server in progress as process 73142
2022-06-30T06:13:31.354233Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-06-30T06:13:59.524843Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-06-30T06:14:48.614092Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 31rSi;4wgt(h复制
11.启动mysql服务
[root@vm lib]# systemctl start mysqld复制
12.使用临时密码登录mysql
[root@vm lib]# mysql -u root -p
Enter password:复制
13.修改当前登录用户密码
mysql> alter user user() identified by 'Abcd@1234';
可以使用alter USER 'root'@'localhost' IDENTIFIED BY 'Abcd@1234';
密码不能少于8位,过于简单。复制
14.新建数据库
mysql> create database sunxiaowen;复制
15.新建用户,授权访问
--创建用户,可以从任意远程主机登陆,使用通配符%
mysql> create user 'sunxiaowen'@'%' identified by '123456';
--显示所有用户
mysql> select user,host from mysql.user;
+------------------+-----------+
| user | host |
+------------------+-----------+
| sunxiaowen | % |
| mysql.infoschema | localhost |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+------------------+-----------+
--将数据库sunxiaowen上的所有权限all privileges授予用户'sunxiaowen'@'%'
mysql> GRANT ALL PRIVILEGES ON sunxiaowen.* TO 'sunxiaowen'@'%';复制
16.安装后配置文件默认在/etc/my.cnf,默认配置如下:
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid复制
17.修改mysql数据目录
--新建目录
[root@vm mysql]# cd home
[root@vm home]# mkdir data
--停止mysql服务进程
[root@vm home]# mysqladmin -u root -p shutdown
--移动原数据目录到新目录
[root@vm home]# mv var/lib/mysql home/data
--编辑my.cnf配置文件
[root@vm mysql]# vim etc/my.cnf
datadir=/home/data/mysql
socket=/home/data/mysql/mysql.sock
--创建连接文件
[root@vm mysql]# ln -s /home/data/mysql/mysql.sock /var/lib/mysql/mysql.sock
--启动mysql服务
[root@vm mysql]# systemctl start mysqld复制
文章转载自云自由,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。
评论
相关阅读
【专家有话说第五期】在不同年龄段,DBA应该怎样规划自己的职业发展?
墨天轮编辑部
1322次阅读
2025-03-13 11:40:53
MySQL8.0统计信息总结
闫建(Rock Yan)
493次阅读
2025-03-17 16:04:03
2月“墨力原创作者计划”获奖名单公布
墨天轮编辑部
465次阅读
2025-03-13 14:38:19
SQL优化 - explain查看SQL执行计划(一)
金同学
394次阅读
2025-03-13 16:04:22
MySQL突然崩溃?教你用gdb解剖core文件,快速锁定“元凶”!
szrsu
368次阅读
2025-03-13 00:29:43
MySQL生产实战优化(利用Index skip scan优化性能提升257倍)
chengang
328次阅读
2025-03-17 10:36:40
MySQL数据库当前和历史事务分析
听见风的声音
294次阅读
2025-04-01 08:47:17
一键装库脚本3分钟极速部署,传统耗时砍掉95%!
IT邦德
239次阅读
2025-03-10 07:58:44
MySQL 生产实践-Update 二级索引导致的性能问题排查
chengang
233次阅读
2025-03-28 16:28:31
MySQL8.0直方图功能简介
Rock Yan
232次阅读
2025-03-21 15:30:53