查看是否安装有mysql
rpm -qa | grep mysql
下载MySQL yum源
wget https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
安装yum源
yum localinstall mysql80-community-release-el7-1.noarch.rpm
更新yum源
yum clean all
yum makecache
创建Mysql账户
groupadd mysql
若提示已经存在 groupadd: group 'mysql' already exists 解决: groupdel mysql 了解详情
若提示无法删除 groupdel: cannot remove the primary group of user 'mysql'
解决方法:
sudo vipw
sudo vipw -s
若vim 保存提示 readonly option is set (add!to override) 你有权限修改文件吗? 如果是root权限,可以 :wq! 了解详情
之后就可以正常执行如下命令了
groupdel mysql
groupadd mysql
useradd -g mysql mysql
开始安装MySQL
yum install mysql-community-server
启动MySQL
systemctl start mysqld
查看初始化密码
cat /var/log/mysqld.log | grep password
登录MySQL
mysql -u root -p
修改初始化密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'yourpassword';
密码一定要大小写字母+数字+符号,如:Aa-123456789
否则报错: ERROR 1819 (HY000): Your password does not satisfy the current policy requirements 了解详情
允许任何主机访问数据库
update user set host = "%" where user = "root";
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'WITH GRANT OPTION;
刷新权限
FLUSH PRIVILEGES;
本地用sqlyog连接遇到这个(可能版本太低)
了解详情
下载Navicat可以正常连接