首页 > 代码库 > 在RHEL6中安装mysql数据库
在RHEL6中安装mysql数据库
今天要给大家演示的是在RHEL6系统中安装mysql数据库,本次实验是在VMware虚拟机中实现。
系统版本:2.6.32-71.el6.i686
[root@wuli ~]# uname -a
Linux wuli.redhat.com 2.6.32-71.el6.i686 #1SMP Wed Sep 1 01:26:34 EDT 2010 i686 i686 i386 GNU/Linux
数据库版本:5.6.20
[root@wuli Downloads]# ls
MySQL-client-5.6.20-1.el6.i686.rpm MySQL-shared-compat-5.6.20-1.el6.i686.rpm
MySQL-server-5.6.20-1.el6.i686.rpm
接下来开始安装数据库,如果是下载的捆绑式的rpm软件包,在解压后会发现有好多个软件包,在此我只安装server和client两个包。在此需要注意的是,在安装之前需要安装一个RHEL兼容包,即shared-compat包。
[root@wuli Downloads]# rpm -ivhMySQL-shared-compat-5.6.20-1.el6.i686.rpm
Preparing... ########################################### [100%]
1:MySQL-shared-compat ########################################### [100%]
默认系统里面给安装了mysql-libs-5.1.47-4.el6.i686软件包,直接卸载会提示有包依赖,在安装完shared-compat之后就可以把它卸载掉,否则会影响安装。
[root@wuli Downloads]# rpm -e mysql-libs
创建MySQL系统管理用户:
[root@wuli Downloads]# groupadd mysql
[root@wuli Downloads]# useradd -g mysqlmysql
[root@wuli Downloads]# passwd mysql
Changing password for user mysql.
New password:mysql(这里密码设置为mysql)
BAD PASSWORD: it is too short
BAD PASSWORD: is too simple
Retype new password:mysql
passwd: all authentication tokens updatedsuccessfully.
[root@wuli Downloads]#
接下来安装MySQL-client-5.6.20-1.el6.i686.rpm和MySQL-server-5.6.20-1.el6.i686.rpm两个软件包。
[root@wuli Downloads]# rpm -ivhMySQL-server-5.6.20-1.el6.i686.rpm
Preparing... ########################################### [100%]
1:MySQL-server ########################################### [100%]
[root@wuli Downloads]# rpm -ivhMySQL-client-5.6.20-1.el6.i686.rpm
Preparing... ###########################################[100%]
1:MySQL-client ########################################### [100%]
启用MySQL服务:
[root@wuli Downloads]# service mysql start
Starting MySQL................ [ OK ]
[root@wuli Downloads]#
首先需要获取登录的随机密码,方法如下:
[root@wuli Downloads]# more/root/.mysql_secret
# The random password set for the root userat Fri Aug 8 05:18:49 2014 (local t
ime): qC1eXKeP3JTEgxzL
[root@wuli Downloads]#
使用首次获取随机密码登录MySQL数据库,然后修改登录密码,方法如下:
[root@wuli Downloads]# mysql -uroot -pqC1eXKeP3JTEgxzL
Warning: Using a password on the commandline interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.20
Copyright (c) 2000, 2014, Oracle and/or itsaffiliates. All rights reserved.
Oracle is a registered trademark of OracleCorporation and/or its
affiliates. Other names may be trademarksof their respective
owners.
Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ toclear the current input statement.
mysql>
设置登录密码为mysql(这里设置为mysql)
mysql> set password=password(‘mysql‘);
Query OK, 0 rows affected (0.07 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql>
修改安装目录权限:
[root@wuli Downloads]# chown -R mysql:mysql/usr/share/mysql
[root@wuli Downloads]# chown -R mysql:mysql/var/lib/mysql
为mysql添加环境变量:
[root@wuli ~]# vim .bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startupprograms
PATH=$PATH:$HOME/bin
export PATH
export
exportDATADIR=/var/lib/mysql
exportMYSQL_HOME=/usr/share/mysql
停止启动mysql:
[root@wuli ~]# mysqladmin -uroot -pshutdown
Enter password:mysql
[root@wuli ~]#
[root@wuli ~]#/usr/share/mysql/mysql.server start --user=mysql
Starting MySQL. [ OK ]
到这里整个安装步骤已经完成了,但是我们经常来配置或登录mysql数据库的时候,不可能每次都在服务器上来配置,很多情况会通过终端来登录服务器,默认mysql服务器禁止从其他终端来登录它。
解决方法如下:
首先登录到数据库
[root@wuli ~]#mysql –uroot –p
Enter password:mysql
mysql> use mysql
Reading table information for completion oftable and column names
You can turn off this feature to get aquicker startup with -A
Database changed
mysql> update user set host=‘%‘ wherehost=‘localhost‘;
Query OK, 1 row affected (0.06 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.06 sec)
接下来我们再来通过客户端来登录服务器:
成功登录。
如果遇到下面提示符,原因是由于服务器开启了防火墙导致的,解决方法:关闭防火墙即可。
我们可以查看安装的数据库版本:
到此,整个实验就完成了,欢迎来到MySQL的世界^_^!
本文出自 “wuli鈥檚 blog” 博客,请务必保留此出处http://wuli03960405.blog.51cto.com/1470785/1537201