1. 版本
- centos:7.5 (64位)
- mysql:5.7.26 (64位)
2. 安装步骤
-
Set1: 检测系统是否存在
# yum list installed | grep mysql
-
Set2: 删除系统自带mysql及其依赖
如果Set1检测存在,执行下面删除操作,如果不存在直接跳过执行Set3
# yum -y remove mysql-libs.x86_64
-
Set3: 下载mysql官方yum repository
# wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
-
Set4: 安装rpm
# yum -y install mysql57-community-release-el7-10.noarch.rpm
-
Set5: 安装mysql服务器
# yum -y install mysql-community-server
至此安装完成
3. 配置
-
启动mysql服务
# service mysqld start
-
查看初始密码
# grep "password" /var/log/mysqld.log A temporary password is generated for root@localhost: eySGLs._15Tc
-
重置密码
-
初始密码登录
# mysql -u root -p
-
设置新密码
# SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');
-
设置密码时提示错误
# ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
此问题与validate_password_policy值的设置有关
validate_password_policy值默认为1,即MEDIUM,所以要求密码必须符合长度要求,大小写,特殊字符
policy Tests performed 0 or LOW length 1 or MEDIUM Length; numeric, lowercase/uppercase, and special characters 2 or STRONG Length; numeric, lowercase/uppercase, and special characters; dictionary file - 修改密码校验策略
这样,对密码要求就只有长度了,重新执行上面修改密码操作,提示成功。# set global validate_password_policy=0; Query OK, 0 rows affected (0.00 sec)
- 刷新权限
# flush privileges; // 退出mysql命令行 # exit;
-
-
查看是否开机自启,并设置
// centos6 查看、设置 --此处系统为centos7,直接用centos7的方式查看与设置 # chkconfig --list | grep mysqld Note: This output shows SysV services only and does not include native systemd services. SysV configuration data might be overridden by native systemd configuration. If you want to list systemd services use 'systemctl list-unit-files'. To see services enabled on particular target use 'systemctl list-dependencies [target]'. # chkconfig mysqld on Note: Forwarding request to 'systemctl enable mysqld.service'. // centos7 查看、设置 通过systemctl list-unit-files 查看 # systemctl list-unit-files | grep mysqld mysqld.service enabled mysqld@.service disabled # systemctl enable mysqld
-
修改字符集为UTF-8
# vim /etc/my.cnf 在[mysql]部分添加: character-set-server=utf8 在文件末位新增[client]段,并在后增加: default-character-set=utf8
-
修改完毕重启服务
# service mysqld restart
-
允许外部链接访问
# mysql -u root -p Enter password: mysql> grant all privileges on *.* to 'root'@'%' identified by '你的密码' with grant option; ERROR 1819 (HY000): Your password does not satisfy the current policy requirements // 此处出现安全策略问题,再次修改 # set global validate_password_policy=0; Query OK, 0 rows affected (0.00 sec) # flush privileges; Query OK, 0 rows affected (0.00 sec) # exit; // 完成!!