1.检查是否安装过MySQL
yum list installed | grep mysql
注意:如果已安装,则清除
yum -y remove mysql-libs.x86_64
2.下载mysql5.7 rpm源
wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm
3.安装下载好的rpm包
rpm -ivh mysql57-community-release-el7-8.noarch.rpm
4.安装mysql,发现提示,y到底
yum install mysql-server
5.查看下mysql的版本,确定是否安装成功
mysql -V
6.运行MySQL
service mysqld start
7.获取MySQL随机初始化密码
grep "password" /var/log/mysqld.log
8.登录MySQL
mysql -u root -p
粘贴密码
9.更改root密码
SET PASSWORD = PASSWORD('你的新密码'); (“需要带数字,大写字母,小写字母,特殊符号”)
ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER; ("密码永不过期")
flush privileges; ("刷新MySQL的系统权限相关表")
–根据个人需求,设置数据库用户在所有ip下以及在本地可访问,以下用root用户做演示
grant all privileges on *.* to root@"%" identified by "你的密码";
grant all privileges on *.* to root@"localhost" identified by "你的密码";
flush privileges;
–新建用户
CREATE USER 'icare_dev'@'%' IDENTIFIED BY '******';
–用户授权
添加用户权限: GRANT ALL ON databasename.tablename TO 'icare_dev'@'%';
撤销用户权限: REVOKE ALL ON databasename.tablename TO 'icare_dev'@'%';
删除用户及权限 :drop user 'icare_dev'@'%';