环境
CentOS7
MySQL5.7
准备
-
(1)安装wget
yum install wget
-
(2)下载所需package
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-common-5.7.28-1.el7.x86_64.rpm wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-libs-5.7.28-1.el7.x86_64.rpm wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-client-5.7.28-1.el7.x86_64.rpm wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-server-5.7.28-1.el7.x86_64.rpm
-
(3)删除mariadb
查询看是否有安装mariadb,如果有就删除
rpm -qa | grep mariadb
rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64
安装
-
安装所需package
yum install libaio rpm -ivh mysql-community-common-5.7.28-1.el7.x86_64.rpm rpm -ivh mysql-community-libs-5.7.28-1.el7.x86_64.rpm rpm -ivh mysql-community-client-5.7.28-1.el7.x86_64.rpm rpm -ivh mysql-community-server-5.7.28-1.el7.x86_64.rpm
启动
-
启动服务
systemctl start mysqld
-
查看启动状态
systemctl status mysqld
-
设置开机自启动
systemctl enable mysqld
配置
-
查找初始缺省密码
cat /var/log/mysqld.log | grep password
-
用查找的密码登陆
mysql -u root -p
-
修改密码安全等级和长度
这一步可以不做,如果不做密码就需要设置数字,字母大小写,特殊符号8位以上
set global validate_password_policy=0; set global validate_password_length=4;
-
修改密码
set PASSWORD = PASSWORD('123456');
退出重新用新的password登陆
-
允许远程root登陆
缺省不允许远程用root登陆,如果要允许需要修改配置
可以看到root对应的Host是localhost,只允许本地访问以root登陆
mysql -u root -p
切换数据库
use mysql;
设置访问权限
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
刷新访问权限表
flush privileges;
再确认一下user表
可以看到有root对应Host为%的记录了重新验证登陆
mysql -u root -p -h 192.168.21.163
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。