MySQL
yum安装
介绍Linux下使用Yum安装Mysql
- 在mysql官网下载mysql的yum源
wget https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm
- 上传到centos中并执行本地安装
yum localinstall mysql80-community-release-el7-3.noarch.rpm
- 安装服务
yum -y install mysql-community-server
- 查看Mysql服务的状态
service mysqld status
- 开启Mysql服务
service mysqld start
- 查看配置文件,找到日志目录
vim /etc/my.cnf
- 查看日志文件,找到初始密码
vim /var/log/mysqld.log
- 登录MySQL
mysql -u root -p
- 修改初始密码(Root.123)大小写字母加数字加符号
alter user 'root'@'localhost' identified by 'Root.123';
远程授权
说明如果是阿里云的ECS,则需要自己在安全组中开发3306端口号
授权远程登录账号:
- 以下是5.7版本的方法,实测在8.0以上版本不行
- 第一个xxxx是用户名,第二个xxxx是密码,意思是通过xxxx用户和密码可以从任何主机连接到mysql服务器。
grant all privileges on *.* to 'xxxx'@'%' identified by 'xxxxxx' with grant option;
grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
- 权限立即生效
flush privileges;
- 以下是适用于8.0版本的授权:
- 进入数据库
use mysql;
- 查看当前用户信息
select host, user, authentication_string, plugin from user;
- 修改MySQL对密码的要求
set global validate_password.policy=0;
set global validate_password.length=1;
- 创建远程连接的用户
#create user 'xxxx'@'x' identified by 'xxxxxxx';
create user 'kang'@'%' identified by 'kang123';
- 修改密码加密规则,mysql8.0默认的加密方式是“caching_sha2_password”,而navicat只支持以前的"mysql_native_password"
ALTER USER 'kang'@'%' IDENTIFIED WITH mysql_native_password BY 'kang123';
- 查看加密规则是否改变
select host, user, authentication_string, plugin from user;
- 给新用户添加权限,最后刷新权限
GRANT ALL PRIVILEGES ON *.* TO 'kang'@'%';
flush privileges;