1.去官网下载合适的yum源安装包
https://dev.mysql.com/downloads/repo/yum/
2.yum 本地安装
命令:yum localinstall mysql57-community-release-el7-11.noarch.rpm
3.检查mysql源是否安装成功
命令:yum repolist enabled | grep "mysql.*-community.*"
4.安装mysql
命令:yum install mysql-community-server
5.启动MySQL服务
命令:systemctl start mysqld
6.查看mysql的启动状态
命令:systemctl status mysqld
7.开机启动
命令:
systemctl enable mysqld
systemctl daemon-reload
8.修改root本地登录密码:
a.在/var/log/mysqld.log找到生成的默认密码:grep 'temporary password' /var/log/mysqld.log
b.登录:mysql -uroot -p;
c. 修改密码:set password for 'root'@'localhost'=password('*******');
备注:这个设置的为复杂密码,如果想改为简单密码,需重新设置密码策略。
http://www.linuxidc.com/Linux/2016-09/135288.htm(设置方法可以在这里查看)
8.添加远程登录用户
命令: GRANT ALL PRIVILEGES ON *.* TO 'username'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
查看是否设置成功:
命令:
use mysql;
select host,user from user;
出现类似的信息即为设置成功
9.配置默认编码为utf8
修改/etc/my.cnf配置文件,在[mysqld]下添加编码配置,如下所示:
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
重新启动mysql服务,查看数据库默认编码如下所示:
参考:http://www.linuxidc.com/Linux/2016-09/135288.htm