获取官方社区版下载地址 https://dev.mysql.com/downloads/repo/yum/
1、下载mysql安装包 :wget https://repo.mysql.com//mysql80-community-release-el8-1.noarch.rpm
2、将下载好的安装包挂载到本地:yum localinstall mysql80-community-release-el8-1.noarch.rpm
3、查看是否挂载成功:yum repolist enabled | grep "mysql.*-community.*"
4、禁用centos8.0自带的mysql模块:yum module disable mysql(若是centos7可跳过)
5、安装mysql:yum install mysql-community-server
6、启动mysql服务 systemctl start mysqld.service
查看mysql服务启动状态 systemctl status mysqld.service
mysql服务相关命令
启动服务:service mysqld start ->(systemctl start mysqld.service) 停止服务:service mysqld stop -> (systemctl stop mysqld.service)
重启服务:service mysqld restart -> (systemctl restart mysqld.service)
查看服务状态:service mysqld status -> (systemctl status mysqld.service)
设置mysql开机自启:
systemctl enable mysqld
systemctl daemon-reload
7、修改mysql密码并开放远程连接
查看mysql安装时生成的随机密码:grep 'temporary password' /var/log/mysqld.log
8、登录mysql
mysql -uroot -p'刚获取到的随机密码'
9、安装mysql后第一次登录需要修改密码
初始时密码等级要求是MEDIUM,位数也是要求8位,可以先设置一个符合要求的密码,比如Ztx2079#..
ALTER USER 'root' @'localhost' IDENTIFIED BY '你的密码';
然后查看当前默认规则
SHOW VARIABLES LIKE 'validate_password%';
重新设置规则
set global validate_password.policy=0;
set global validate_password.length=4;
然后再更新root简单密码
ALTER USER 'root' @'localhost' IDENTIFIED BY '123456';
10、开放mysql远程访问
创建权限记录:
CREATE user 'root'@'%' IDENTIFIED BY '你的密码';
授权:
GRANT ALL PRIVILEGES ON *.* TO 'root' @'%' WITH GRANT OPTION;
修改密码过期策略:
ALTER USER 'root' @'localhost' IDENTIFIED BY '你的密码' PASSWORD EXPIRE NEVER;
重新修改密码:
ALTER USER 'root' @'%' IDENTIFIED WITH mysql_native_password BY '你的密码';
刷新权限:
FLUSH PRIVILEGES;
测试:
参考:
https://www.jianshu.com/p/bcdd4789d6a6
https://www.jianshu.com/p/804cd2d2cdbf
https://blog.csdn.net/weixin_43845335/article/details/88982571