CentOS-7下安装MySQL5.6.22

一 安装环境

(1)CentOS版本:CentOS-7

查看方法:

[root@bogon 桌面]# cat /etc/redhat-release

CentOS Linux release 7.0.1406 (Core)

来源:官网下载

下载地址:http://www.centos.org/

(2)MySQL版本:MySQL-5.6.22

来源:官网下载

下载地址:https://edelivery.oracle.com/EPD/Search/handle_go

或者http://pan.baidu.com/s/1dDu6n9R

名称:MySQL Database 5.6.22 RPM for Oracle Linux / RHEL 7 x86 (64bit)

二 安装方式选择

在网上搜了一下,Linux下安装MYSQL有三种方式:

1 通过yum命令在线下载安装

2 下载离线rpm安装包安装

3 下载源码编译安装

方式1不打算用,因为我们大部分项目服务器是不能直接上Internet的,网上关于在线安装的教程很多,方式3对于只要应用MYSQL的人来说没必要多此一举。

三 安装步骤

1. 解压下载的zip包,会发现有以下几个rpm包:

MySQL-client-advanced-5.6.22-1.el7.x86_64.rpm

MySQL-devel-advanced-5.6.22-1.el7.x86_64.rpm

MySQL-embedded-advanced-5.6.22-1.el7.x86_64.rpm

MySQL-server-advanced-5.6.22-1.el7.x86_64.rpm

MySQL-shared-advanced-5.6.22-1.el7.x86_64.rpm

MySQL-shared-compat-advanced-5.6.22-1.el7.x86_64.rpm

MySQL-test-advanced-5.6.22-1.el7.x86_64.rpm

 

2. 卸载MariaDB

如果直接点击rpm包安装会得到错误提示。因为CentOS的默认数据库已经不再是MySQL了,而是MariaDB,为什么呢?

MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可。开发这个分支的原因之一是:甲骨文公司收购了MySQL后,有将MySQL闭源的潜在风险,因此社区采用分支的方式来避开这个风险。MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松成为MySQL的代替品。

查看当前安装的mariadb包:

[root@bogon 桌面]# rpm -qa | grep mariadb

将它们统统强制性卸载掉:

[root@bogon 桌面]# rpm -e --nodeps mariadb-libs-5.5.35-3.el7.x86_64

[root@bogon 桌面]# rpm -e --nodeps mariadb-5.5.35-3.el7.x86_64

[root@bogon 桌面]# rpm -e --nodeps mariadb-server-5.5.35-3.el7.x86_64

 

3. 安装MYSQL

双击下面三个包进行自动安装:

MySQL-client-advanced-5.6.22-1.el7.x86_64.rpm

MySQL-devel-advanced-5.6.22-1.el7.x86_64.rpm

MySQL-server-advanced-5.6.22-1.el7.x86_64.rpm

提示:其实第二个包devel我也不知道是干什么的,也不知道是不是必须的(上网搜了一下应该不是必须的),没有测试是否必须就已经点来装上了,也不想花时间去测试是否必须了,有测试过的朋友麻烦留言告知。

 

4. 启动MYSQL

[root@bogon 桌面]#service mysql start

得到错误:ERROR!The server quit without updating PID file

我们这里主要是因为:selinux惹的祸,如果是centos系统,默认会开启selinux。解决方法是关闭它,打开/etc/selinux/config,把SELINUX=enforcing改为SELINUX=disabled后存盘退出重启机器。

然后再启动mysql就没问题了:

[root@bogon 桌面]#service mysql start

查看MySQL运行状态:

[root@bogon 桌面]# service mysql status

SUCCESS! MySQL running (2377)

 

5. 默认root用户登录MYSQL

[root@bogon 桌面]# mysql -u root -p

Enter password:

ERROR 1045 (28000):Access denied for user 'root'@'localhost' (using password: YES)

发现有有错误,然后在网上查了一下说使用下面命令修改root初始化密码:

[root@bogon 桌面]# /usr/bin/mysqladmin -u root password 'passok'

/usr/bin/mysqladmin: connect to server at'localhost' failed

error: 'Accessdenied for user 'root'@'localhost' (using password: NO)'

发现MYSQL数据库默认的root用户还是没办法设置密码进行登录,需要做一下操作:

 

最近新装好的mysql在进入mysql工具时,总是有错误提示:
# mysql -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

使用网上介绍的方法修改root用户的密码:
# mysqladmin -uroot -p password 'newpassword'
Enter password:
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: YES)'

现在终于被我找到了解决方法,如下(请先测试方法三,谢谢!):
方法一:
# /etc/init.d/mysql stop
# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
# mysql -u root mysql
mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';
mysql> FLUSH PRIVILEGES;
mysql> quit

重置MySQL中root用户密码及验证

还是不行,然后在网上又找到一个重置MySQL中root用户密码及验证的方法:

(1) 停止MySQL服务

[root@bogon 桌面]# service mysql stop

Shutting down MySQL.. SUCCESS!

(2) 输入绕过密码认证命令

[root@bogon 桌面]# mysqld_safe --user=mysql --skip-grant-tables--skip-networking &

    执行上面命令后,此会话窗口会出现无反应的状态,需要使用CTRL+C中断会话,检查/var/lib/mysql/DB-Server.err日志,发现也无其它异常信息。没有弄明白该会话窗口为啥会出现无响应状态。

       接着

        

mysql -u root mysql

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

 

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 1

Server version: 5.6.19 MySQL Community Server (GPL)

 

Copyright (c) 2000, 2014, 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> select Host, User, Password,password_expired

    -> from user

    -> where user='root' and host='root' or host='localhost';

+-----------+------+-------------------------------------------+------------------+

| Host      | User | Password                                  | password_expired |

+-----------+------+-------------------------------------------+------------------+

| localhost | root | *A848DE7CCD839E924921BEE41711991DDA0D529E | Y                |

+-----------+------+-------------------------------------------+------------------+

1 row in set (0.00 sec)

 

mysql> update user set password=PASSWORD('p12#456')

    -> where user='root' and host='root' or host='localhost';

Query OK, 1 row affected (0.00 sec)

Rows matched: 1  Changed: 1  Warnings: 0

新设置用户或更改密码后需用flush privileges刷新MySQL的系统权限相关表,否则会出现拒绝访问,还有一种方法,就是重新启动mysql服务器,来使新设置生效。

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

 

mysql> quit

Bye

[root@DB-Server init.d]# /etc/rc.d/init.d/mysql restart

Shutting down MySQL..140722 15:02:27 mysqld_safe mysqld from pid file /var/lib/mysql/DB-Server.pid ended

[  OK  ]

Starting MySQL.[  OK  ]

[2]-  Done                    mysqld_safe --user=mysql --skip-grant-tables --skip-networking

[root@DB-Server init.d]# mysql -u root p

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

[root@DB-Server init.d]# mysql -u root -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 2

Server version: 5.6.19

 

Copyright (c) 2000, 2014, 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>


另外,如果登录mysql数据库后执行脚本遭遇 ERROR 1820 (HY000): You must SET PASSWORD before executing this statement,可以使用重新设置一次密码即可解决问题.

mysql>set password = password('p12#456');




你可能感兴趣的:(CentOS-7下安装MySQL5.6.22)