1.官方下载安装包
2.上传安装包到服务器
将mysql安装在data目录下,将文件上传到/data/mysql目录下,tar解压,重命名为mysql-8.0.21
cd /data
mkdir mysql
rz
tar -xvf mysql-8.0.21-linux-glibc2.12-x86_64.tar.xz
mv mysql-8.0.21-linux-glibc2.12-x86_64 mysql-8.0.21
3.添加系统用户组和用户
我这里已经存在了
groupadd mysql useradd -r -g mysql mysql
4. 新建数据目录和临时目录
进入/data/mysql/mysql-8.0.21 下创建目录并授权
mkdir data tmp
chmod 777 ./data ./tmp
5.新建并修改配置文件
cd support-files
vim my-default.cnf
vim /etc/my.cnf
将以下内容写入
[mysqld]
basedir = /usr/local/tools/mysql-8.0.21
datadir = /usr/local/tools/mysql-8.0.21/data
port = 3306
socket = /usr/local/tools/mysql-8.0.21/tmp/mysql.sock
lower_case_table_names=1
[client]
default-character-set=utf8
socket= /usr/local/tools/mysql-8.0.21/tmp/mysql.sock
[mysql]
default-character-set=utf8
socket= /usr/local/tools/mysql-8.0.21/tmp/mysql.sock
6.修改当前目录为mysql用户
chown -R mysql:mysql ./
7.初始化mysql配置表
进入 /data/mysql/mysql-8.0.21目录下,记录下密码
bin/mysqld --initialize --user=mysql --basedir=/data/mysql/mysql-8.0.21 --datadir=/data/mysql/mysql-8.0.21/data
8.设置开机启动
cp mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql
chkconfig --add mysql
chkconfig --list mysql (检查是否启动成功)
9.配置文件
vim /etc/profile (配置环境变量)
#将这部分内容写入
export PATH=$PATH:/data/mysql/mysql-8.0.21/bin:/data/mysql/mysql-8.0.21/lib
service mysql start
source /etc/profile (执行配置文件)
注:
如果这里有问题,
查看 /etc/my.cnf是不是有问题,(我这里查看的时候路径有问题),修改,并删掉/data/mysql/mysql-8.0.21底下的data和tmp,然后重置密码,也就是第七步
10.进入mysql
mysql -uroot -p-%FZg-#LC1gj
alter user 'root'@'localhost' identified by 'root';(重置为root)
flush privileges
#打开mysql外部链接
mysql->use mysql;
mysql->update user set host = '%' where user ='root';
mysql->flush privileges;
mysql->select 'host' from user where user='root';
11.MySQL8.0登录提示caching_sha2_password问题解决方法
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> SELECT Host, User, plugin from user;
+-----------+------------------+-----------------------+
| Host | User | plugin |
+-----------+------------------+-----------------------+
| % | root | caching_sha2_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session | caching_sha2_password |
| localhost | mysql.sys | caching_sha2_password |
+-----------+------------------+-----------------------+
4 rows in set (0.00 sec)
mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root';
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT Host, User, plugin from user;
+-----------+------------------+-----------------------+
| Host | User | plugin |
+-----------+------------------+-----------------------+
| % | root | mysql_native_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session | caching_sha2_password |
| localhost | mysql.sys | caching_sha2_password |
+-----------+------------------+-----------------------+
4 rows in set (0.00 sec)
引用自:(22条消息) CentOS8 安装MySql 8.0教程_大白猿的专栏-CSDN博客_centos8安装mysql
附加1045密码问题:(22条消息) CentOS8 安装MySql 8.0报1045问题_学不会VUE的小菜鸟的博客-CSDN博客