Linux环境——MySQL安装及配置(5.7版本)

数据库安装包下载地址:https://dev.mysql.com/downloads/mysql/node

选择适合本身的版本,个人环境是Linux  Red Hat Enterprlse Linux (64位),本次安装的是Mysql 5.7版本。mysql

说一下安装中经历的坎坷,开始虚拟机中有默认版本5.1,版本太老,不适用了,而后从网上看教程,须要删除已存在的,好吧,删吧!完过后,正常下载新的版本,当时选择的是最高版本8.0的,下载、安装都完成后,懵逼了,觉得和windows上同样,直接在当前文件夹就能找到mysql的安装后的文件,其实并木有,中间找的过程省略,而后碰到和以前的版本冲突、mysql.sock异常、mysqld文件不存在等问题,从新卸载安装,还会出现部分文件(mysql-community-server-8··)删除不了、mysql_install_db文件不存在各类各类,这中间的百度、必应的找方法解决也是很揪心,说了这么多,说一下终极的解决问题之道吧!——卸载干净再从新安装——(是的,我还重启虚拟机,o(╥﹏╥)o)sql

你可能会问,以前安装的8版本为何又换到了5.7版本,由于我最新版费劲不知道问题在哪,而后,其实5.7也是够用的,还有就是查看部分博客,最新版好像同低版本不连通。总而言之,换成5.7版本成功了!数据库

查看原有版本:rpm -qa|grep mysqlwindows

[root@localhost116 mysql]# rpm -qa|grep mysql
mysql-community-common-5.7.25-1.el6.x86_64
mysql-community-client-5.7.25-1.el6.x86_64
mysql-community-libs-compat-5.7.25-1.el6.x86_64
mysql-community-server-5.7.25-1.el6.x86_64
mysql-community-libs-5.7.25-1.el6.x86_64
[root@localhost116 mysql]# 

这里能够看到存在mysql,版本是5.7的。看到这里,你决定是否删除原有版本,若是不删除,就跳过;删除的继续~~ide

  • 删除/卸载原有版本:

一、rpm  卸载操做ui

rpm -ev mysql-community-server-5.7.25-1.el6.x86_64    #rpm -e 后面接卸载的包名,rpm -ev 能看到卸载的详情
rpm -ev --nodeps mysql-community-server-5.7.25-1.el6.x86_64    #可忽略依赖关系进行卸载

这里补充一点,若是部分文件没法删除, 又找不到解决方法,能够试试先把文件从新安装一次,再进行卸载,亲试可用!this

二、删除其余相关文件spa

whereis mysql                 #查找相关的文件及路径
find / -name mysql            #查找相关的文件及路径
rm -rf  XXXX    #rm -rf 后接要删除的文件路径

 

  • 下载安装新版本:

一、新建mysql文件:rest

mkdir /usr/local/mysql/     #在/usr/local 路径下新建mysql文件夹

二、下载   【 mysql-5.7.25-1.el6.x86_64.rpm-bundle.tar 】到mysql文件夹中,而后进行解压操做,能获得rpm安装包。

解压命令:

tar -xvf XXX.tar
[root@localhost116 mysql]# ls
mysql-5.7.25-1.el6.x86_64.rpm-bundle.tar
mysql-community-client-5.7.25-1.el6.x86_64.rpm
mysql-community-common-5.7.25-1.el6.x86_64.rpm
mysql-community-devel-5.7.25-1.el6.x86_64.rpm
mysql-community-embedded-5.7.25-1.el6.x86_64.rpm
mysql-community-embedded-devel-5.7.25-1.el6.x86_64.rpm
mysql-community-libs-5.7.25-1.el6.x86_64.rpm
mysql-community-libs-compat-5.7.25-1.el6.x86_64.rpm
mysql-community-server-5.7.25-1.el6.x86_64.rpm
mysql-community-test-5.7.25-1.el6.x86_64.rpm
[root@localhost116 mysql]# 

三、安装rpm文件

rpm -ivh  XXX.rpm     #安装文件

这里特别注意的是,安装顺序,common——>libs——>libs-compat——>client——>server,其余的看我的需求,正常安装这几个就够了。

四、启动mysql服务

/etc/init.d/mysqld status    #查看mysql启动状态   或者使用  service mysqld status
/etc/init.d/mysqld start     #启动mysql服务  或者使用  service mysqld start  

注意:用法:/etc/init.d/mysqld   {start|stop|status|restart|condrestart|try-restart|reload|force-reload},service mysqld 同理。

[root@localhost116 ~]# /etc/init.d/mysqld start
初始化 MySQL 数据库: [肯定]
正在启动 mysqld: [肯定] 

mysql 文件默认会安装到【/var/lib/mysql】中,以下

[root@localhost116 mysql]# ls
auto.cnf       ca-key.pem       client-key.pem  ib_logfile0  #innodb_temp  mysql.sock          private_key.pem  server-key.pem  undo_002
binlog.000001  ca.pem           ib_buffer_pool  ib_logfile1  mysql         mysql.sock.lock     public_key.pem   sys
binlog.index   client-cert.pem  ibdata1         ibtmp1       mysql.ibd     performance_schema  server-cert.pem  undo_001
[root@localhost116 mysql]# 

五、访问

默认密码能够在文件 【/var/log/mysqld.log】 中获取,命令:

tail -100f /var/log/mysqld.log

 使用默认密码进行登陆便可。安装完成!!

[root@localhost116 ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.25 MySQL Community Server (GPL)

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> 

异常:

一、ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

因为是默认密码登陆的,操做会提示须要先重置默认密码后才能操做,能够先修改一个复杂的密码过分,如:A1test!123

重置密码命令:

alter user root@'localhost' identified by '新密码';

生效密码及退出:

flush privileges;   #修改生效
exit;       #退出

二、ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

不符合密码规范,修改密码规范,命令:

set global validate_password_policy=0;   #设置所有参数validate_password_policy ,通常默认值是MEDIUM,须要知足密码规范,设置为0后就不须要了。
set global validate_password_length=4; #设置全局参数validate_password_length,通常默认值是8,即最少的密码长度是8,设置为4,即最少的密码长度为4.

 

————————————————————————————————————————————————————————————————————————————

补充:不删除mysql各个文件的方法,安装新的mysql安装文件,后面加--nodeps --force,如:

rpm -ivh mysql-community-client-5.7.25-1.el6.x86_64.rpm --nodeps --force
相关文章
相关标签/搜索