下载并安装MySQL官方的 Yum Repository
wget http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
yum -y install mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql-server
启动MySQL服务
systemctl start mysqld
设置开机自动启动
systemctl enable mysqld
查看是否运行成功
systemctl status mysqld
配置MySQL
此时MySQL已经开始正常运行,不过要想进入MySQL还得先找出此时root用户的密码,通过如下命令可以在日志文件中找出密码:
grep "password" /var/log/mysqld.log
登录mysql root账户
mysql -u root -p
输入初始密码(是上面图片最后面的 no;e!5>>alfg),此时不能做任何事情,因为MySQL默认必须修改密码之后才能操作数据库:
alter user 'root'@'localhost' identified by password('new password');
修改服务器字符集配置
vim /etc/my.cnf
添加保存
character-set-server=utf8
collation-server=utf8_general_ci
重启myql
service mysqld restart
开放远程访问端口(如有需要)
firewall-cmd --zone=public --add-port=3306/tcp --permanentfirewall-cmd --reload
开放远程访问权限(如有需要)
在mysql中执行
grant all privileges on *.* to 'root'@'your ip or *(all)' identified by 'password' with grant option;