安装环境:RedHat6.5
第一步:下载 下载MySQL5.7:第二步:安装
安装前检查服务器是否已安装MySQL,如已安装则将其卸载:[root@worker1 tmp]# rpm -qa|grep mysqlmysql-libs-5.1.71-1.el6.x86_64[root@worker1 tmp]# rpm -e --nodeps mysql-libs-5.1.71-1.el6.x86_64 //卸载
将下载的文件进行解压:
[root@worker1 tmp]# tar -xf mysql-5.7.12-1.el6.x86_64.rpm-bundle.tar
按顺序依次安装:
1. rpm -ivh mysql-community-common-5.7.12-1.el6.x86_64.rpm2. rpm -ivh mysql-community-libs-5.7.12-1.el6.x86_64.rpm3. rpm -ivh mysql-community-devel-5.7.12-1.el6.x86_64.rpm4. rpm -ivh mysql-community-client-5.7.12-1.el6.x86_64.rpm5. rpm -ivh mysql-community-server-5.7.12-1.el6.x86_64.rpm
不出意外,MySQL应该已经安装成功。
第三步:环境变量设置
启动MySQL:service mysqld start
登录:mysql -u root -p,初次登录密码为空,直接回车:
为什么会出现这个错误,原因是因为MySQL5.7中的mysql.user 表中没有Password字段,所以要以安全方式登录,然后修改密码。 解决方法如下: 修改MySQL配置文件:vim /etc/my.cnf,在文件末尾加上:skip-grant-tables,保存后重启MySQL服务:service mysqld restart,然后重新登录。
- 修改密码,用户密码是在名为mysql的database下面: 依次执行以下指令:
mysql> use mysqlmysql> update user set password_expired='N' where user='root’; mysql> update user set authentication_string=password('123456') where user=‘root’;mysql> flush privileges;
- 注意:一定要将my.cnf配置文件之前加的跳过密码检测内容去掉,重启服务;
其他:
- 编码设置:vim /etc/my.cnf,文件末尾加上编码内容default-character-set=utf8
- 允许远程访问MySQL: 赋予任何主机访问数据的权限 mysql>grant all privileges on . to ‘root’@’%’with grant option; 会报错:ERROR 1133 (42000): Can’t find any matching row in the user table 其实如果事先在mysql.user表中存在root用户就正常了,或,将这句末尾加上identified by ‘密码’ 也就正常了。如下面的命令行 mysql>grant all privileges on . to ‘root’@’%’identified by ‘123456’ with grant option;
- 更改密码策略:
mysql> set global validate_password_length=0; --更改密码长度 mysql> set global validate_password_policy=0; --更改密码策略为LOW