更新源
$ wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
$ sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
$ yum update
安装
$ sudo yum install mysql-server
$ sudo systemctl start mysqld
启动
$ systemctl start mysqld
重启
$ systemctl restart mysqld
关闭
$ systemctl stop mysqld
重置密码
- 停止mysql并设置免密
$ sudo systemctl stop mysqld
- 如果需要支持短密码(可选)
在/etc/my.cnf
文件中添加validate_password=off
- 免密启动mysql
$ sudo mysqld_safe --skip-grant-tables &
- 登录
$ mysql -u root
- 更新密码
mysql>use mysql;
mysql>update user SET PASSWORD=PASSWORD("password") WHERE USER='root';
mysql>flush privileges;
mysql>exit
允许远程连接
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
mysql>FLUSH PRIVILEGES;
$ firewall-cmd --zone=public --add-port=3306/tcp --permanent
$ systemctl restart firewalld.service