Linux安装MySQL5.7
2019-09-28 本文已影响0人
死海以东
上传压缩包
压缩包已经上传我的网盘,可以保存下来以后用哦,下载链接:https://pan.baidu.com/s/1MSySB4EwB0jkWEHNrc99cQ
提取码:uomn
复制这段内容后打开百度网盘手机App,操作更方便哦
为了管理方便及桌面没那么乱,建议上传到 /usr/local/src 目录下。
上传成功后进入/usr/local/src 目录下解压包:
[root@vm1 src]# unzip db_source.zip
解压完成后ls查看,会在目录下看到解压出来的目录mysql-5.7.24和 mysql-5.7.25,以安装mysql-5.7.25为例:
[root@vm1 src]# cd mysql-5.7.25
[root@vm1 mysql-5.7.25]# ls
mysql-5.7.25.tar.xz mysql_install_5.7.25.sh xtcsh.sh
(安装包) (安装脚本) (检查环境脚本)
[root@vm1 mysql-5.7.25]# sh -x xtcsh.sh // -x是为了检查脚本是否有错,可加可不加。
[root@vm1 mysql-5.7.25]# sh -x mysql_install_5.7.25.sh //执行安装脚本,等待安装,假设没出错的情况下,看到请手动执行source /etc/profile,于是
[root@vm1 mysql-5.7.25]# source /etc/profile
[root@vm1 mysql-5.7.25]# grep "password" /usr/local/mysqld/log/mysql_error.log //过滤密码
2019-04-20T03:55:21.290298Z 1 [Note] A temporary password is generated for root@localhost: zhEL(6c)I1x3
2019-04-20T06:07:37.616036Z 0 [Note] Shutting down plugin 'sha256_password'
2019-04-20T06:07:37.616041Z 0 [Note] Shutting down plugin 'mysql_native_password'
2019-04-20T06:19:48.282741Z 2 [Note] Access denied for user 'root'@'localhost' (using password: NO)
2019-04-20T06:37:18.111211Z 3 [Note] Access denied for user 'root'@'localhost' (using password: NO)
由上面可以看出我的随机密码为:
zhEL(6c)I1x3
当然,是随机生成的密码,每个人的都是不一样的,于是我们进行如下操作:
[root@vm1 tmp]# mysql -uroot -p"zhEL(6c)I1x3"
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
发生错误,拒绝root'@'localhost用户访问,于是只好破解密码进行登录修改密码,步骤如下:
修改配置文件 /etc/my.conf ,在[mysqld]下添加skip-grant-tables 以进行跳过密码验证
[root@vm1 mysql-5.7.25]# vi /etc/my.cnf
[mysqld]
skip-grant-tables
保存退出后重启服务使修改生效,
[root@vm1 mysql-5.7.25]# systemctl restart mysqld
重启后再次登录,
[root@vm1 mysql-5.7.25]# mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.25-log Source distribution
Copyright (c) 2000, 2019, 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>
出现上面的界面说明破解成功了,为了系统安全,所以我们需要进行加密,修改密码的方式有几种,alter方法会受到密码安全的限制,而update不受限制,所以以update修改密码为123456为例:
mysql> update mysql.user set authentication_string=PASSWORD('123456') where User='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
#修改成功后一定要记得 flush privileges; 刷新,否则修改不生效。
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)