1.在 /use/local下 创建mysql文件夹
mkdir mysql
2.切换到mysql文件夹下
cd mysql
3.下载mysql
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.21-linux-glibc2.12-x86_64.tar.xz
4.解压mysql
tar xvJf mysql-8.0.21-linux-glibc2.12-x86_64.tar.xz
5.重命名文件夹
mv mysql-8.0.21-linux-glibc2.12-x86_64 /usr/local/mysql-8.0
5.在/use/local/mysql-8.0下创建data文件夹 存储文件
mkdir data
6.创建用户组以及用户和密码
groupadd mysql
useradd -g mysql mysql
7.授权用户
chown -R mysql.mysql /usr/local/mysql-8.0
8.切换到在/use/local/mysql-8.0/bin目录下
cd bin
9.初始化基础信息
./mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/ --initialize
得到临时密码:bJ9n-wRcZFa+
10.编辑my.cnf文件
vi /etc/my.cnf
编辑内容:
[mysqld]
basedir=/usr/local/mysql-8.0/
datadir=/usr/local/mysql-8.0/data/
socket=/tmp/mysql.sock
character-set-server=UTF8MB4
11./use/local/mysql-8.0/添加mysqld服务到系统
cp -a ./support-files/mysql.server /etc/init.d/mysql
12.授权以及添加服务
chmod +x /etc/init.d/mysql
chkconfig --add mysql
13.启动mysql
service mysql start
service mysql stop
重启:service mysql restart
14.查看启动状态
service mysql status
15.将mysql命令添加到服务
ln -s /usr/local/mysql-8.0/bin/mysql /usr/bin
16.登录mysql mysql -uroot -p 密码使用之前随机生成的密码
mysql -u root -p
17.修改root密码 其中123456是新的密码自己设置
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'yunDream123456';
18.执行 使密码生效
flush privileges;
19.选择mysql数据库
use mysql;
20.修改远程连接并生效
update user set host='%' where user='root';
flush privileges;