参考来源:
http://blog.csdn.net/liyf155/article/details/61419623
1.下载:
wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.12-1.el6.x86_64.rpm-bundle.tar
2.安装:
[root@localhost Desktop]# rpm -qa|grep mysql # 查看是否已安装
mysql-libs-5.1.61-4.el6.x86_64
[root@localhost Desktop]# rpm -e --nodeps mysql-libs-5.1.61-4.el6.x86_64 #卸载
解压:tar -xf mysql-5.7.12-1.el6.x86_64.rpm-bundle.tar
顺序依次安装:
rpm -ivh mysql-community-common-5.7.12-1.el6.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.12-1.el6.x86_64.rpm
rpm -ivh mysql-community-devel-5.7.12-1.el6.x86_64.rpm
rpm -ivh mysql-community-client-5.7.12-1.el6.x86_64.rpm
rpm -ivh mysql-community-server-5.7.12-1.el6.x86_64.rpm
安装最后一个包的时候报错:
error: Failed dependencies:
libnuma.so.1()(64bit) is needed by mysql-community-server-5.7.12-1.el6.x86_64
缺少依赖包:
numactl
下载:wget http://mirror.centos.org/centos/6/os/x86_64/Packages/numactl-2.0.9-2.el6.x86_64.rpm
安装:rpm -ivh numactl-2.0.9-2.el6.x86_64.rpm
安装成功
继续上次安装完成
启动mysql服务:service mysqld start
[root@localhost mysql5.7]# service mysqld start Initializing MySQL database: [ OK ] Installing validate password plugin: [ OK ] Starting mysqld: [ OK ] [root@localhost mysql5.7]#
登陆:mysql -u root -p,初次登录密码为空,直接回车
[root@localhost mysql5.7]# mysql -u root -p Enter password: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
为什么会出现这个错误,原因是因为MySQL5.7中的mysql.user 表中没有Password字段,所以要以安全方式登录,然后修改密码。
解决方法如下:
修改MySQL配置文件:vim /etc/my.cnf,在文件末尾加上:skip-grant-tables,保存后重启MySQL服务:service mysqld restart,然后重新登录。
[root@localhost mysql5.7]# service mysqld restart Stopping mysqld: [ OK ] Starting mysqld: [ OK ] [root@localhost mysql5.7]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 3 Server version: 5.7.12 MySQL Community Server (GPL) Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or 'h' for help. Type 'c' to clear the current input statement. mysql>
修改密码:
use mysql;
update user set password_expired='N' where user='root’;
update user set authentication_string=password('123456') where user=’root‘;
flush privileges;
修改MySQL配置文件:vim /etc/my.cnf,去掉文件末尾:skip-grant-tables
重启MySQL服务:service mysqld restart
其他:
- 编码设置:vim /etc/my.cnf,文件末尾加上编码内容default-character-set=utf8
- 允许远程访问MySQL:
赋予任何主机访问数据的权限:grant all on *.* to "root"@"%" identified by "123456"; - 修改密码策略(可以使用简单密码):
set global validate_password_policy=0;
set global validate_password_mixed_case_count=0;
set global validate_password_number_count=3;
set global validate_password_special_char_count=0;
set global validate_password_length=3;
SHOW VARIABLES LIKE 'validate_password%';