1.使用系统的root账户
2.切换到/use/local 目录下
3.下载mysql
?wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.21-linux-glibc2.12-x86_64.tar.xz
也可以直接在官方下载最新版本官方下载选择linux
4.解压mysql
[root@localhost local]# tar -zxvf mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz
5.重命名文件夹
[root@localhost local]# mv mysql-8.0.11-linux-glibc2.12-x86_64 mysql-8.0.11
5.创建data文件夹 存储文件
[root@localhost local]# cd mysql-8.0.11
[root@localhost mysql-8.0.11]# mkdir data
6.创建用户组以及用户和密码
[root@localhost mysql-8.0.11]# groupadd mysql
[root@localhost mysql-8.0.11]# useradd -g mysql mysql
7.授权用户
[root@localhost mysql-8.0.11]# chown -R mysql.mysql /usr/local/mysql-8.0.11
8.切换到bin目录下
[root@localhost mysql-8.0.11]# cd bin
9.初始化基础信息
[root@localhost bin]# ./mysqld --user=mysql --basedir=/usr/local/mysql-8.0.11 --datadir=/usr/local/mysql-8.0.11/data/ --initialize
得到临时密码
2022-10-14T01:56:52.910060Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: -*_zQWmi>8:H
10.编辑my.cnf文件
[root@localhost bin]# vi /etc/my.cnf
注释mysqld_safe 并修改以下修改信息
basedir=/usr/local/mysql-8.0.11/
datadir=/usr/local/mysql-8.0.11/data/
socket=/tmp/mysql.sock
character-set-server=UTF8MB4
11.添加mysqld服务到系统
[root@localhost mysql-8.0.11]# cp -a ./support-files/mysql.server /etc/init.d/mysql
12.授权以及添加服务
[root@localhost mysql-8.0.11]# chmod +x /etc/init.d/mysql
[root@localhost mysql-8.0.11]# chkconfig --add mysql
13.启动mysql
[root@localhost mysql-8.0.11]# service mysql start
14.查看启动状态
[root@localhost mysql-8.0.11]# service mysql status
15.将mysql命令添加到服务
[root@localhost mysql-8.0.11]# ln -s /usr/local/mysql-8.0.11/bin/mysql /usr/bin
16.登录mysql mysql -uroot -p 密码使用之前随机生成的密码
[root@localhost mysql-8.0.11]# mysql -uroot -p
17.修改root密码其中123456是新的密码自己设置
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
18.执行 使密码生效
mysql> flush privileges;
19.选择mysql数据库
mysql> use mysql;
20.修改远程连接并生效
mysql> update user set host='%' where user='root';
mysql> flush privileges;
标签:11,8.0,local,linux,mysql8.0,mysql,root,localhost From: https://www.cnblogs.com/Galaxy1/p/16790785.html