1.先检查是否安装过mysql,如果没有可进行下面的操作.
2.下载mysql的安装包
cd /usr/local 到这个目录下
mkdir mysql 新建一个mysql文件夹
cd mysql 到mysql文件夹中
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.15-1.el7.x86_64.rpm-bundle.tar 下载安装包
3.解压安装包
tar -xvf mysql-8.0.15-1.el7.x86_64.rpm-bundle.tar
4.安装响应组件,common、libs、client、server
rpm -ivh mysql-community-common-8.0.15-1.el7.x86_64.rpm --nodeps --force
rpm -ivh mysql-community-libs-8.0.15-1.el7.x86_64.rpm --nodeps --force
rpm -ivh mysql-community-client-8.0.15-1.el7.x86_64.rpm --nodeps --force
rpm -ivh mysql-community-server-8.0.15-1.el7.x86_64.rpm --nodeps --force
效果如图:
5.初始化数据库
mysqld --initialize;
chown mysql:mysql /var/lib/mysql -R;
systemctl start mysqld.service;
systemctl enable mysqld;
6.登录数据库,查看默认密码
cat /var/log/mysqld.log | grep password
如图:红色框框内的是密码
7.登录数据库
mysql -uroot -p
填写如上图的密码
8.修改密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
9.添加用户提供远程访问
create user 'caojiantao'@'%' identified with mysql_native_password by '123456';
grant all privileges on *.* to 'caojiantao'@'%' with grant option;
flush privileges;
exit 退出
安装成功.