Linux系统安装mysql数据库

    关于Linux系统的软件安装方法有很多种,目前常用是二进制安装,rpm安装,yum安装,源代码安装,对这几种安装方法都有优点和缺点,现在将这些安装方法总结如下:

 

二进制包:安装简单,可以任意选择购软件版本,不需要编译,直接初始化就行了

rpm安装:此安装方法需要解决依赖包,可以安装指定软件版本

yum安装:只能安装当前系统的软件包,如果用网络源必须要连接外网

源代码:安装比较复杂,也需要解决依赖问题,不过可以指定需要的模块和启动某个功能

 

一.用rpm安装指定的mysql数据库

系统:Centos 6.5 64位

软件:MySQL-5.6.21  64位

[root@node1 ~]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/MySQL-client-5.6.21-1.el6.x86_64.rpm               --下载软件包

[root@node1 ~]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/MySQL-devel-5.6.21-1.el6.x86_64.rpm

[root@node1 ~]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/MySQL-embedded-5.6.21-1.el6.x86_64.rpm

[root@node1 ~]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/MySQL-server-5.6.21-1.el6.x86_64.rpm

[root@node1 ~]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/MySQL-shared-5.6.21-1.el6.x86_64.rpm

[root@node1 ~]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/MySQL-shared-compat-5.6.21-1.el6.x86_64.rpm

[root@node1 ~]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/MySQL-test-5.6.21-1.el6.x86_64.rpm

[root@node1 ~]# yum localinstall MySQL-* -y       --安装mysql并解决包依赖问题

[root@node1 ~]# vim /root/.mysql_secret             --查看mysql初始化密码

# The random password set for the root user at Wed Nov 12 10:25:55 2014 (local time): _x4DfGXT2B8eBUW_       --红色的是密码,此密码是动态的

[root@node1 ~]# /etc/init.d/mysql restart      --启动服务
Shutting down MySQL.. SUCCESS! 
Starting MySQL.. SUCCESS!

[root@node1 ~]# mysql -u root -p           --登陆并输入初始密码
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.21 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 version();         --查看版本
+-----------+
| version() |
+-----------+
| 5.6.21    |
+-----------+
1 row in set (0.00 sec)

mysql>

 

二.二进制包安装

1.下载和解压mysql数据库

[root@node1 ~]# wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.4-m14-linux-glibc2.5-x86_64.tar.gz

[root@node1 ~]# tar -xvf mysql-5.7.4-m14-linux-glibc2.5-x86_64.tar.gz -C /usr/local/mysql-5.7.4

 

2.创建mysql用户和修改软件的权限

[root@node1 ~]# useradd -r -M -s /sbin/nologin mysql

[root@node1 ~]# chown -R mysql  /usr/local/mysql-5.7.4

[root@node1 ~]# chgrp -R mysql /usr/local/mysql-5.7.4 

 

3.安装和初始化数据库

[root@node1 ~]# cd /usr/local/mysql-5.7.4/

[root@node1 mysql-5.7.4]# scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql-5.7.4/ --datadir=/usr/local/mysql-5.7.4/data/            --必须在mysql根目录安装mysql,否则出错

[root@node1 mysql-5.7.4]# cp -a ../support-files/my-default.cnf  /etc/my.cnf

[root@node1 mysql-5.7.4]# cp -a ../support-files/mysql.server  /etc/init.d/mysqld

[root@node1 mysql-5.7.4]# cd bin/

[root@node1 bin]# ./mysqld_safe --user=mysql &

[root@node1 bin]# chkconfig  --add mysql

[root@node1 bin]# /etc/init.d/mysqld restart
Shutting down MySQL..                                      [  OK  ]
Starting MySQL...                                              [  OK  ]

[root@node1 bin]#          

 

三.用yum源安装

[root@node2 ~]# mkdir /mnt/cdrom/          

[root@node2 ~]# mount /dev/cdrom  /mnt/cdrom/    --挂载光盘镜像

[root@node2 ~]# yum repolist         --更新yum仓库

[root@node2 ~]# yum install mysql mysql-server  mysql-devel mysql-utils -y       --只能安装系统自带的软件










本文转自 z597011036 51CTO博客,原文链接:http://blog.51cto.com/tongcheng/1553660,如需转载请自行联系原作者
上一篇:Codevs 1065 01字符串


下一篇:RabbitMq安装成功后执行命令报错(Error: unable to connect to node 'rabbit@DESKTOP-LPKSION': nodedown)