下载安装包
mysql-5.7.21-1.el7.x86_64.rpm-bundle.tar
解压
批量安装rpm包
rpm -Uvh --force --nodeps *rpm
首先关闭mysql服务,修改配置文件
service mysqldstop
vim /etc/my.cnf
在my.cnf中增加:
skip-grant-tables #添加这句话,这时候登入mysql就不需要密码
开启mysql服务
service mysqld start
mysql -u root -p #输入命令回车进入,出现输入密码提示直接回车
设置mysql密码
set password for root@localhost = password('123456');
出现错误:
ERROR 1290 (HY000): The MySQL server is running with the
--skip-grant-tables option so it cannot execute this statement
#更新权限
flush privileges;
重新设置
set password for root@localhost = password('123456');
flush privileges; #更新权限
quit; #退出
service mysqld stop # 停止mysql服务, 恢复mysql配置
vim /etc/my.cnf #修改配置文件
# Disabling symbolic-links is recommended to prevent assorted security risks
# skip-grant-tables # 注释掉这句话
symbolic-links=0
service mysqld start # 启动mysql服务
mysql -u root -p # 输入新密码登录
设置mysql开机自启
systemctl enable mysqld
设置远程登陆
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456789' WITH GRANT OPTION;
出现错误更新权限即可
flush privileges; #更新权限
注意:linux环境下外部链接需要关闭防火墙