1.获取MySQL的yum源
下载地址如:https://dev.mysql.com/downloads/repo/yum/
2.下载和安装mysql源
[~]# wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
[~]# yum -y localinstall mysql57-community-release-el7-11.noarch.rpm
3.在线安装MySQL
[~]# yum -y install mysql-community-server
4.重启MySQL服务器
[~]# systemctl start mysqld
5.设置开机启动
[~]# systemctl enable mysqld
[~]# systemctl daemon-reload
6.修改root本地登录密码
从 /var/log/mysqld.log 中找到初始密码,找到如下文字“A temporary password is generated for root@localhost:”
冒号后面即为初始密码
使用命令登录
[~]# mysql -uroot -p
修改root账户密码
> ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码,必须包含英文大小写字母,数字和特殊字符,且至少8位';
7.配置默认编码为utf8
修改/etc/my.cnf配置文件,在[mysqld]下添加编码配置,如下所示:
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
编辑完成后,记得重启MySQL
[~]# systemctl restart mysqld
8.创建远程可访问的账户
> create user 新用户名 identified by '新用户密码';
对账户授权
> grant all privileges on 库名.表名 to '新用户名'@'%'identified by '新用户密码' with grant option;
当需要授权新用户所有库所有表的权限时,可以将库名.表名设置为*.*
刷新mysql权限表
> flush privileges ;
9.测试
从其他地址链接 mysql -h xxxxx -u用户名 -p
参考与推荐: