环境:redhat6.5,mysql5.7.18。
不同版本的mysql安装方式会有较大的差别详见最后
1,配置yum对mysql的支持
rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
2,安装yum
yum install yum-utils -y
3,启用mysql5.7的yum源
yum-config-manager --disable mysql56-community
yum-config-manager --enable mysql57-community-dmr
4,验证将要安装的yum源
yum repolist enabled | grep mysql
如果显示
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
mysql-connectors-community MySQL Connectors Community 36
mysql-tools-community MySQL Tools Community 47
mysql57-community-dmr MySQL 5.7 Community Server Development Milesto 183
则证明设置成功!
5,执行安装
yum install mysql-community-server
一路确认(Y),下载相关依赖rpm,下载需要一定时间 ,执行安装。
(1/5): mysql-community-client-5.7.18-1.el6.x86_64.rpm | 23 MB 01:14
(2/5): mysql-community-common-5.7.18-1.el6.x86_64.rpm | 328 kB 00:01
(3/5): mysql-community-libs-5.7.18-1.el6.x86_64.rpm | 2.1 MB 00:06
(4/5): mysql-community-libs-compat-5.7.18-1.el6.x86_64.rpm | 1.6 MB 00:05
(5/5): mysql-community-server-5.7.18-1.el6.x86_64.rpm (53%) 45% [================================================ ] 331 kB/s | 68 MB 04:18 ETA
提示
Complete!
安装完成。
6,禁用selinux(没有理解)
setenforce 0
sed -i '/^SELINUX=/c\SELINUX=disabled' /etc/selinux/config
7,第一次启动服务(会初始化ROOT用户数据)
service mysqld start
此时输入mysql提示
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
8,停止MySQL服务
service mysqld stop
9,修改跳过授权验证方式启动MySQL
mysqld_safe --skip-grant-tables
如果提示
2017-07-11T00:56:58.195385Z mysqld_safe Logging to '/var/log/mysqld.log'.
2017-07-11T00:56:58.207820Z mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
则证明可以不输入密码访问mysql
10,访问mysql
mysql
11,切换数据库
use mysql;
12,修改密码
update user set authentication_string=password('123456') where user='root';
13,使最新配置生效
flush privileges;
14,测试
[root@bogon ~]# mysql -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.18
Copyright (c) 2000, 2017, 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>
本机访问,通过。
以下是关于远程访问的配置↓
1,登录mysql并输入上述密码。
2,执行允许远程访问的sql
grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
此时会提示
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
3,需要再一次重新设置密码(崩溃!)
SET PASSWORD = PASSWORD('12345678');
4,再次执行2
5,更新配置
flush privileges;
6,退出mysql。
7,永久关闭防火墙。
chkconfig iptables off
8,重启
reboot
9,测试
写在最后的一些细节问题:
1,mysql5.6是不会生成mysql_secret文件,可以直接登录。
2,mysql5.7.x - mysql5.7.7之间是生成mysql_secret文件 初始密码在这里面(/root/.mysql_secret)。
3,mysql5.7.7之后没有mysql_secret文件,密码在/var/log/mysqld.log(仔细找)。
4,可以不去找/var/log/mysqld.log,但是要去修改跳过授权验证方式启动MySQL,修改root(mysql的root)密码。
5,5.7之后密码字段的column为authentication_string而不是password。
6,如果提示
Your password does not satisfy the current policy requirements
参考
http://www.cnblogs.com/ivictor/p/5142809.html