先查看自己的版本
# uname -r
http://mirrors.sohu.com/mysql/MySQL-5.7/
2.6.32-431.23.3.el6.x86_64
到网站找el6.x86_64 的mysql 安装包
[root@iZ25av9xi4hZ opt]# wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.13-1.el6.x86_64.rpm-bundle.tar
mysql 版本下载地址 http://mirrors.sohu.com/mysql/,如图所示
安装:
安装顺序
1、mysql-community-common-5.7.13-1.el6.x86_64.rpm
2、mysql-community-libs-5.7.13-1.el6.x86_64.rpm
3、mysql-community-libs-compat-5.7.13-1.el6.x86_64.rpm
4、mysql-community-client-5.7.13-1.el6.x86_64.rpm
5、mysql-community-server-5.7.13-1.el6.x86_64.rpm
[root@iZ25av9xi4hZ opt]# rpm -ivh mysql-community-common-5.7.13-1.el6.x86_64.rpm
warning: mysql-community-common-5.7.13-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ########################################### [100%]
1:mysql-community-common ########################################### [100%]
[root@iZ25av9xi4hZ opt]# rpm -ivh mysql-community-libs-5.7.13-1.el6.x86_64.rpm
warning: mysql-community-libs-5.7.13-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ########################################### [100%]
1:mysql-community-libs ########################################### [100%]
[root@iZ25av9xi4hZ opt]# rpm -ivh mysql-community-libs-compat-5.7.13-1.el6.x86_64.rpm
warning: mysql-community-libs-compat-5.7.13-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ########################################### [100%]
1:mysql-community-libs-co########################################### [100%]
[root@iZ25av9xi4hZ opt]# rpm -ivh mysql-community-client-5.7.13-1.el6.x86_64.rpm
warning: mysql-community-client-5.7.13-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ########################################### [100%]
1:mysql-community-client ########################################### [100%]
[root@iZ25av9xi4hZ opt]# rpm -ivh mysql-community-server-5.7.13-1.el6.x86_64.rpm
warning: mysql-community-server-5.7.13-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ########################################### [100%]
1:mysql-community-server ########################################### [100%]
[root@f90140fd8427 lib]# useradd mysql
[root@f90140fd8427 lib]# su mysql
[mysql@f90140fd8427 lib]$ mysqld --initialize
二、启动mysql
[root@iZ25av9xi4hZ opt]# /etc/init.d/mysqld start
Initializing MySQL database: [ OK ]
Installing validate password plugin: [ OK ]
Starting mysqld: [ OK ]
查找mysql
[root@iZ25av9xi4hZ local]# find / -name mysql -print
/usr/lib64/mysql
/usr/share/mysql mysql默认安装目录:/usr/share/mysql
/usr/bin/mysql
/etc/logrotate.d/mysql
/var/lib/mysql data默认目录:/var/lib/mysql
/var/lib/mysql/mysql
三、修改密码
3.1修改配置文件,第一次跳过验证
3.2修改my.cnf配置文件
# sudo vi /etc/my.cnf
在[mysqld]的段中加上一句:skip-grant-tables,
如下:
[mysqld] datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
skip-grant-tables
3.3启动mysql
#/etc/init.d/mysqld start
如果/etc/init.d/mysqld 则采用下面的方式
[root@f90140fd8427 mysql]# su mysql
[mysql@f90140fd8427 mysql]$ mysqld &
[1] 983
[mysql@f90140fd8427 mysql]$ exit
exit
[root@f90140fd8427 mysql]# ps -ef | grep mysql
mysql 983 1 3 06:59 ? 00:00:00 mysqld
root 1013 773 0 06:59 ? 00:00:00 grep --color=auto mysql
[root@f90140fd8427 mysql]# mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.15 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>
3.4 登录修改密码
# mysql -uroot mysql
MySQL 5.7.6 以及最新版本:
# mysql> update user set authentication_string=PASSWORD('newpass') where User='root';
MySQL 5.7.5 或更早之前的版本r:
# mysql> update user set password=PASSWORD('newpass') where User='root';
FLUSH PRIVILEGES;
3.5修改外网权限
针对所有服务器都可以访问,修改成这样
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
如果只针对能192.168.13.56服务器能够访问,修改成这样
GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.13.56' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
3.6刷新数据库
FLUSH PRIVILEGES;
3.7退出,修改/etc/my.cnf,删除原先的跳过验证,skip-grant-tables,删除
3.8 重启 数据库
#/etc/init.d/mysqld restart
3.9如果出现下面情况
You must reset your password using ALTER USER statement before executing this statement.
bogon:~ root# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 112
Server version: 5.7.14
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
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
解决方案
mysql> SET PASSWORD = PASSWORD("123456");
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> FLUSH PRIVILEGES;