CentOS-6.5-x86_64-minimal 搭建mysql-5.6.29

来源:互联网 发布:接收chinanet的软件 编辑:程序博客网 时间:2024/05/21 07:05

一、mysql简介

说到数据库,我们大多想到的是关系型数据库,比如mysql、oracle、sqlserver等等,这些数据库软件在windows上安装都非常的方便,在Linux上如果要安装数据库,咱不得不首先推荐的是mysql数据库了,而且Mysql数据库的第一个版本就是发行在Linux系统上的。

MySQL是一个关系型数据库管理系统,由瑞典MySQL AB公司开发,目前属于Oracle公司。MySQL是一种关联数据库管理系统,关联数据库将数据保存在不同的表中,而不是将所有数据放在一个大仓库内,这样就增加了速度并提高了灵活性。MySQL的SQL语言是用于访问数据库的最常用标准化语言。MySQL软件采用了双授权政策(本词条“授权政策”),它分为社区版和商业版,由于其体积小、速度快、总体拥有成本低,尤其是开放源码这一特点,一般中小型网站的开发都选择MySQL作为网站数据库。由于其社区版的性能卓越,搭配PHP和Apache可组成良好的开发环境。

在Linux上安装mysql数据库,我们可以去其官网上下载mysql数据库的rpm包,http://dev.mysql.com/downloads/mysql/5.6.html#downloads,大家可以根据自己的操作系统去下载对应的数据库文件,目前最新的版本是5.6.10了。

在这里我是通过yum来进行mysql数据库的安装的,通过这种方式进行安装,可以将跟mysql相关的一些服务、jar包都给我们安装好,所以省去了很多不必要的麻烦!!!

二、卸载掉原有mysql

因为mysql数据库在Linux上实在是太流行了,所以目前下载的主流Linux系统版本基本上都集成了mysql数据库在里面,我们可以通过如下命令来查看我们的操作系统上是否已经安装了mysql数据库

[root@xiaoluo ~]# rpm-qa | grep mysql  // 这个命令就会查看该操作系统上是否已经安装了mysql数据库

有的话,我们就通过 rpm -e 命令 或者 rpm -e --nodeps 命令来卸载掉

[root@xiaoluo ~]# rpm-e mysql  //普通删除模式

[root@xiaoluo ~]# rpm-e --nodeps mysql  //强力删除模式,如果使用上面命令删除时,提示有依赖的其它文件,则用该命令可以对其进行强力删除

在删除完以后我们可以通过 rpm -qa | grep mysql 命令来查看mysql是否已经卸载成功!!

三、安装mysql

安装mysql前需要查询系统中含有的有关mysql的软件。

rpm -qa | grep -imysql  //grep -i是不分大小写字符查询,只要含有mysql就显示

屏幕显示:

mysql-libs-5.1.71-1.el6.i686  //它是好几个软件的依赖,其中在mini版本中postfix软件依赖mysql-libs,网络上很多建议都是直接删除,

yum remove mysql-libs 或者 rpm -e --nodeps mysql-libs-5.1.71-1.el6.i686,总觉得这样做不好。

查找mysql官方资料,得到安装方法是用MySQL-shared-compat将mysql-libs-5.1.71-1.el6.i686替换为同版本后在安装mysql。

下载mysql地址:http://dev.mysql.com/downloads/mysql/

CentOSRedHatLinux系列的,因此选择RedHatLinux(见红线地方),网页会自动变成RedHatLinux有关的mysql下载:

需要下载2个内容,一个是MySQL-5.6.29-1.el6.x86_64.rpm-bundle.tar,这个是几个程序的合集包,另一个是MySQL-shared-compat-5.6.29-1.el6.x86_64.rpm,这个是软件包包括MySQL 3.23MySQL 4.0的共享库。如果你安装了应用程序动态连接MySQL 3.23,但是你想要升级到ySQL 4.0而不想打破库的从属关系,则安装该软件包而不要安装MySQL-shared。从MySQL 4.0.13起包含该安装软件包。

2个文件上传到CentOS中,解压MySQL-5.6.29-1.el6.x86_64.rpm-bundle.tar

 

#tar xvf MySQL-5.6.29-1.el6.x86_64.rpm-bundle.tar

MySQL-client-5.6.29-1.el6.x86_64.rpm

MySQL-devel-5.6.29-1.el6.x86_64.rpm

MySQL-shared-5.6.29-1.el6.x86_64.rpm

MySQL-test-5.6.29-1.el6.x86_64.rpm

MySQL-server-5.6.29-1.el6.x86_64.rpm

MySQL-embedded-5.6.29-1.el6.x86_64.rpm

#ls -l

total 415068

-rw-r--r--. 1 rootroot  210442240 Nov 11 11:12 MySQL-5.6.29-1.el6.x86_64.rpm-bundle.tar

-rw-r--r--. 1 7155wheel  17813608 Sep 12 16:25MySQL-client-5.6.29-1.el6.x86_64.rpm

-rw-r--r--. 1 7155wheel   3131328 Sep 12 16:25 MySQL-devel-5.6.29-1.el6.x86_64.rpm

-rw-r--r--. 1 7155wheel  83106000 Sep 12 16:25MySQL-embedded-5.6.29-1.el6.x86_64.rpm

-rw-r--r--. 1 7155wheel  54611632 Sep 12 16:26MySQL-server-5.6.29-1.el6.x86_64.rpm

-rw-r--r--. 1 7155wheel   1878756 Sep 12 16:27MySQL-shared-5.6.29-1.el6.x86_64.rpm

-rw-r--r--. 1 rootroot    4141488 Nov 18 14:42MySQL-shared-compat-5.6.29-1.el6.x86_64.rpm

-rw-r--r--. 1 7155wheel  49887932 Sep 12 16:27 MySQL-test-5.6.29-1.el6.x86_64.rpm

 

安装MySQL-shared-compat替换mysql-libs,如果不替换,在删除mysql-libs,会提示postfix依赖于mysql-libs

# rpm -iMySQL-shared-compat-5.6.29-1.el6.x86_64.rpm

# rpm -qa | grep -imysql

mysql-libs-5.1.71-1.el6.i686

MySQL-shared-compat-5.6.29-1.el6.x86_64

# yum removemysql-libs

测试MySQL-server安装,提示需要安装perl

# rpm -ivh --testMySQL-server-5.6.29-1.el6.x86_64.rpm

# yum install perl

测试安装过程中可能还会有如下错误:

error: Faileddependencies:

        libnuma.so.1()(64bit) is needed byMySQL-server-5.6.29-1.el6.x86_64

        libnuma.so.1(libnuma_1.1)(64bit) isneeded by MySQL-server-5.6.29-1.el6.x86_64

        libnuma.so.1(libnuma_1.2)(64bit) isneeded by MySQL-server-5.6.29-1.el6.x86_64

下载: numactl-2.0.9-2.el6.x86_64.rpm

# rpm -ivhnumactl-2.0.9-2.el6.x86_64.rpm

安装MySQL-serverMySQL-client

 

# rpm -ivh  MySQL-server-5.6.29-1.el6.x86_64.rpm

Preparing...               ########################################### [100%]

   1:MySQL-server          ########################################### [100%]

………………

………………

A RANDOM PASSWORD HASBEEN SET FOR THE MySQL root USER !

You will find thatpassword in '/root/.mysql_secret'.

You must change thatpassword on your first connect,

no other statementbut 'SET PASSWORD' will be accepted.

See the manual for the semantics of the 'password expired' flag.

Also, the account for the anonymous user has been removed.

In addition, you can run:

  /usr/bin/mysql_secure_installation

………………

………………

# rpm -ivh  MySQL-client-5.6.29-1.el6.x86_64.rpm

Preparing...               ########################################### [100%]

   1:MySQL-client          ########################################### [100%]

 

在安装MySQL-server,见上面的一段话,大意是全新安装设置的root密码在/root/.mysql_secret中,这是一个随机密码,你需要运行/usr/bin/mysql_secure_installation,删除anonymous用户。当然不建议用root用户来运行,rpm包已经建了一个mysql用户,可以使用这个用户:

 

#more .mysql_secret

# The random passwordset for the root user at Tue Nov 18 22:57:46 2014 (local t

ime):NljqL63OYlGo5cqy    <– 得到root访问mysql的密码:NljqL63OYlGo5cqy

# service mysql start

Starting MySQL...SUCCESS!

#/usr/bin/mysql_secure_installation --user=mysql

NOTE: RUNNING ALLPARTS OF THIS SCRIPT IS RECOMMENDEDFOR ALL MySQL

      SERVERS INPRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

 

In order to log into MySQL to secure it, we'llneed the current

password for the root user. If you've just installed MySQL, and

you haven't set theroot password yet, the password will be blank,

so you should justpress enter here.

 

Enter currentpassword for root (enterfornone):    <–使用刚才得到的root的密码NljqL63OYlGo5cqy

OK, successfully usedpassword, moving on...

 

Setting the rootpassword ensures that nobody can log into the MySQL

root user without theproper authorisation.

 

You already have aroot password set, so you can safely answer 'n'.

 

Change the rootpassword? [Y/n] y  <– 是否更换root用户密码,输入y并回车,强烈建议更换

New password:      <– 设置root用户的密码

Re-enter new password:    <– 再输入一次你设置的密码

Password updatedsuccessfully!

Reloading privilegetables..

 ... Success!

 

 

By default, a MySQL installation has an anonymous user, allowinganyone

to log into MySQLwithout having to have a user account createdfor

them.  This is intended only for testing, and to make the installation

go a bitsmoother.  You should remove them beforemoving into a

productionenvironment.

 

Remove anonymoususers? [Y/n] y   <– 是否删除匿名用户,生产环境建议删除,所以输入y并回车

 ... Success!

 

Normally, root shouldonly be allowed to connect from 'localhost'. This

ensures that someonecannot guess at the root password from the network.

 

Disallow root loginremotely? [Y/n] y    <–是否禁止root远程登录,根据自己的需求选择Y/n并回车,建议禁止

 ... Success!

 

By default, MySQL comes with a database named 'test' that anyonecan

access.  This is also intended only for testing, and should be removed

before moving into aproduction environment.

 

Remove test databaseand access to it? [Y/n] y   <– 是否删除test数据库,输入y并回车

 - Dropping test database...

 ... Success!

 - Removing privileges on test database...

 ... Success!

 

Reloading theprivilege tables will ensure that all changes made so far

will take effectimmediately.

 

Reload privilegetables now? [Y/n] y   是否重新加载权限表,输入y并回车

 ... Success!

 

 

 

 

All doneIf you've completed all of the above steps, your MySQL

installation shouldnow be secure.

 

Thanks for using MySQL!

 

 

Cleaning up...

 

至此,MySQL已经安装完成,最后看一下是否已将MySQL加到开机服务里:

 

#  chkconfig

auditd          0:off   1:off  2:on    3:on    4:on   5:on    6:off

blk-availability        0:off  1:on    2:on    3:on   4:on    5:on   6:off

crond           0:off   1:off   2:on   3:on    4:on    5:on   6:off

ip6tables       0:off   1:off   2:on   3:on    4:on    5:on   6:off

iptables        0:off   1:off   2:on   3:on    4:on    5:on   6:off

iscsi           0:off   1:off   2:off  3:on    4:on    5:on   6:off

iscsid          0:off   1:off   2:off  3:on    4:on    5:on   6:off

lvm2-monitor   0:off   1:on    2:on   3:on    4:on    5:on   6:off

mdmonitor       0:off   1:off   2:on   3:on    4:on    5:on   6:off

multipathd      0:off   1:off   2:off  3:off   4:off   5:off  6:off

mysql           0:off   1:off   2:on   3:on    4:on    5:on   6:off   <-看到这个OK了

netconsole      0:off   1:off   2:off  3:off   4:off   5:off  6:off

netfs           0:off   1:off   2:off  3:on    4:on    5:on   6:off

network         0:off   1:off   2:on   3:on    4:on    5:on   6:off

postfix         0:off   1:off   2:on   3:on    4:on    5:on   6:off

rdisc           0:off   1:off   2:off  3:off   4:off   5:off  6:off

restorecond     0:off   1:off   2:off  3:off   4:off   5:off  6:off

rsyslog         0:off   1:off   2:on   3:on    4:on    5:on   6:off

saslauthd       0:off   1:off   2:off  3:off   4:off   5:off  6:off

sshd            0:off   1:off   2:on   3:on    4:on    5:on   6:off

udev-post      0:off   1:on    2:on   3:on    4:on    5:on   6:off

 

MySQL安装后涉及的目录如下:

目录

目录中的内容

/usr/bin

客户端程序和脚本

/usr/sbin

Mysqld服务器

/var/lib/mysql

数据库的日志文件

/usr/share/info

信息格式手册

/usr/share/man

Unix 手册页

/usr/include/mysql

包括(标题)的文件

/usr/lib/mysql

mysqllib

/usr/share/mysql

杂项的支持文件,包括错误消息)字符设置的文件,示例配置文件,SQL数据库安装

/usr/share/sql-bench

基准

安装完毕

 

四、密码修改

可能出现如下:Access denied for user 'root'@'localhost'

# mysql -u root -p

Enter password:

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

解决办法:

# mysqld_safe --user=root --skip-grant-tables --skip-networking &

# mysql -u root

mysql> show tables

mysql> update user setpassword=password('123456') where user='root';

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

mysql> quit

五 数据库远程连接开启方法

1)      修改防火墙

a)  关闭防火墙

#service iptablesstop

b)  打开防火墙开发数据库端口

配置防火墙,开启3306端口

#vi /etc/sysconfig/iptables
-A INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -jACCEPT(允许3306端口通过防火墙)
/etc/init.d/iptables restart(重启防火墙使配置生效)

2)     修改用户访问权限

mysql> grantall privileges on *.* to 'root'@'%' identified by '123456';

mysql> flushprivileges;

 

这里我直接用mysql workbench进行连接



可以远程访问了。
0 0