MySQL:MySQL的安装

一、Linux:MySQL的源码安装

1、安装前的准备 

在安装之前需要安装一下必备的包和工具

  • gcc/g++:MySQL5.6开始,需要使用g++进行编译。
  • cmake:MySQL5.5开始,使用cmake进行工程管理,cmake需要2.8以上版本。
  • bison:MySQL语法解析器需要使用bison进行编译。
  • ncurses-devel:用于终端操作的开发包。
  • zlib:MySQL使用zlib进行压缩

功能需要的包

  • libxml:用于xml输入输出方式的支持。
  • opensll:使用opensll安全套接字通信。
  • dtrace:用于诊断MySQL问题。

有关于MySQL编译参数

  • CMAKE_BUILD_TYPE编译的版本类型:RelWithDebInfo和Debug,不同之处是RelWithDebInfo会进行优化。
  • CMAKE_INSTALL_PREFIX指定make install安装的目标路径。
  • SYSCONFDIR指定配置文件的默认路径。
  • MYSQL_DATADIR指定data目录的默认路径。
  • WITH_DEBUG指定是否有debugging信息,一般用于源码调试时,打开WITH_DEBUG,生产环境关闭。
  • ENABLED_PROFILING指定是否可以使用show profile显示操作执行的详细信息。
  • DEFAULT_CHARSET指定默认字符集,可以在启动的配置文件中指定。
  • DEFAULT_COLLATION指定默认字符比较、排序的规则。
  • WITH_EXTRA_CHARSETS指定其他可能使用的字符集。
  • INSTALL_LAYOUT指定安装的布局类型。
  • WITH_storage_STORAGE_ENGIN指定编译支持的存储引擎,默认支持MyISAM,MERGE,MEMORY,CSV存储引擎。更多详细参数可参考http://dev.mysql.com/doc/refman/5.5/en/source-configuration-options.html 

 本次安装环境

[root@wulaoer ~]# cat /etc/issue
CentOS release 6.5 (Final)
Kernel \r on an \m
[root@wulaoer ~]# uname -a
Linux wulaoer 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
MySQL版本:5.6.12-log Source distribution

安装目录为:/usr/local/mysql/

数据目录为:/data/mysqldata

存储引擎包括:MEMORY,MyISAM,InnoDB等

字符集为:UTF8

2、源码安装MySQL

先安装需要用到的库:

[root@wulaoer ~]# yum -y install gcc-c++ gcc 
[root@wulaoer ~]# yum -y install ncurses-devel

 下载所需软件包:

将下载的文件都放到/usr/local/src目录下,如下

[root@wulaoer ~]# cd /usr/local/src/ 
[root@wulaoer src]# wget http://www.cmake.org/files/v2.8/cmake-2.8.11.1.tar.gz --no-check-certificate
[root@wulaoer src]# wget http://ftp.gnu.org/gnu/bison/bison-2.7.tar.gz
[root@wulaoer src]# wget http://ftp.gnu.org/gnu/m4/m4-1.4.16.tar.gz
[root@wulaoer src]#  wget http://www.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.12.tar.gz/from/http://cdn.mysql.com/ 

 安装cmake编译器

[root@wulaoer src]# tar -zxf cmake-2.8.11.1.tar.gz 
[root@wulaoer src]# cd cmake-2.8.11.1
[root@wulaoer cmake-2.8.11.1]# ./bootstrap 
[root@wulaoer cmake-2.8.11.1]# make && make install

 检查cmake是否安装成功

[root@wulaoer cmake-2.8.11.1]# which cmake
/usr/local/bin/cmake
 安装m4
[root@wulaoer src]# tar -zxf m4-1.4.16.tar.gz  
[root@wulaoer src]# cd m4-1.4.16
[root@wulaoer m4-1.4.16]# ./configure 
[root@wulaoer m4-1.4.16]# make && make install 

安装bison

[root@wulaoer src]# tar -zxf bison-2.7.tar.gz 
[root@wulaoer src]# cd bison-2.7
[root@wulaoer bison-2.7]# ./configure && make && make install
 创建mysql用户与组,相关目录
[root@wulaoer ~]# /usr/sbin/groupadd mysql
[root@wulaoer ~]# /usr/sbin/useradd -g mysql mysql
[root@wulaoer ~]# mkdir -p /usr/local/mysql/
[root@wulaoer ~]# chown -R mysql:mysql /usr/local/mysql
[root@wulaoer ~]# mkdir -p /data/mysqldata
[root@wulaoer ~]# chown -R mysql:mysql /data/mysqldata

安装mysql

[root@wulaoer ~]# cd /usr/local/src/
[root@wulaoer src]# tar -zxf mysql-5.6.12.tar.gz 
[root@wulaoer src]# export CFLAGS="-O3 -g -fno-exceptions -static-libgcc -fno-omit-frame-pointer -fno-strict-aliasing"
[root@wulaoer src]# export CXXFLAGS="-O3 -g -fno-exceptions -fno-rtti -static-libgcc -fno-omit-frame-pointer -fno-strict-aliasing"
[root@wulaoer src]# export CXX=g++
[root@wulaoer mysql-5.6.12]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql/
                            -DMYSQL_UNIX_ADDR=/tmp/mysql.sock
                            -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
                            -DWITH_EXTRA_CHARSETS=utf8,gbk
                            -DWITH_PERFSCHEMA_STORAGE_ENGINE=1
                            -DWITH_FEDERATED_STORAGE_ENGINE=1
                            -DWITH_PARTITION_STORAGE_ENGINE=1
                            -DWITH_ARCHIVE_STORAGE_ENGINE=1
                            -DMYSQL_DATADIR=/data/mysqldata/
                            -DSYSCONFDIR=/usr/local/mysql/
                            -DWITH_SSL=bundled
                            -DENABLED_LOCAL_INFILE=1
                            -DWITH_INNOBASE_STORAGE_ENGINE=1
                            -DWITH_BLACKHOLE_STORAGE_ENGINE=1
                            -DENABLE_DOWNLOADS=1
[root@wulaoer mysql-5.6.12]# make && make install 

  初始化数据库

[root@wulaoer mysql-5.6.12]# cd /usr/local/mysql/
[root@wulaoer mysql]# ./scripts/mysql_install_db --user=mysql --ldata=/data/mysqldata 

 3、安装后的收尾工作

配置运行环境

[root@wulaoer ~]# vi /etc/profile 
PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH
export PATH
[root@wulaoer ~]# source /etc/profile

 创建开机启动

[root@wulaoer ~]# cd /usr/local/mysql/
[root@wulaoer mysql]# cp support-files/my-default.cnf /etc/my.cnf
cp:是否覆盖"/etc/my.cnf"? y
[root@wulaoer mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@wulaoer mysql]# chkconfig --level 35 mysqld on
[root@wulaoer ~]# /etc/init.d/mysqld start
 
Starting MySQL.. ERROR! The server quit without updating PID file (/usr/local/mysql/data/wulaoer.pid).
 以上错误解决方法进mysql安装目录执行[root@wulaoer mysql]# scripts/mysql_install_db --user=mysql 
[root@wulaoer mysql]# /etc/init.d/mysqld start
 
Starting MySQL. SUCCESS!
 设置数据库密码
[root@wulaoer ~]# mysqladmin -u root password 'root'
[root@wulaoer ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.12 Source distribution
二、YUM安装

 在yum安装之前需要设置以下网络yum源,参考点击这里

 在安装之前要看以下系统有没有自带的mysql是否已经安装。

[root@wulaoer ~]# yum list installed | grep mysql
mysql.x86_64            5.1.73-5.el6_6  @base                                   
mysql-libs.x86_64       5.1.73-5.el6_6  @base                                   
mysql-server.x86_64     5.1.73-5.el6_6  @base   
[root@wulaoer ~]# yum -y remove mysql-libs.x86_64
当出现Complete!时候说明已经卸载完成,可以重新查看以下
[root@wulaoer ~]# yum list installed | grep mysql
[root@wulaoer ~]# 

 使用yum list | grep mysql 查看yum库上的mysql版本信心

[root@wulaoer ~]# yum list | grep mysql 
apr-util-mysql.x86_64                    1.3.9-3.el6_0.1                base    
bacula-director-mysql.x86_64             5.0.0-13.el6                   base    
bacula-storage-mysql.x86_64              5.0.0-13.el6                   base    
dovecot-mysql.x86_64                     1:2.0.9-19.el6_7.2             updates 
freeradius-mysql.x86_64                  2.2.6-6.el6_7                  updates 
libdbi-dbd-mysql.x86_64                  0.8.3-5.1.el6                  base    
mod_auth_mysql.x86_64                    1:3.0.0-11.el6_0.1             base    
mysql.x86_64                             5.1.73-5.el6_6                 base    
mysql-bench.x86_64                       5.1.73-5.el6_6                 base    
mysql-connector-java.noarch              1:5.1.17-6.el6                 base    
mysql-connector-odbc.x86_64              5.1.5r1144-7.el6               base    
mysql-devel.i686                         5.1.73-5.el6_6                 base    
mysql-devel.x86_64                       5.1.73-5.el6_6                 base    
mysql-embedded.i686                      5.1.73-5.el6_6                 base    
mysql-embedded.x86_64                    5.1.73-5.el6_6                 base    
mysql-embedded-devel.i686                5.1.73-5.el6_6                 base    
mysql-embedded-devel.x86_64              5.1.73-5.el6_6                 base    
mysql-libs.i686                          5.1.73-5.el6_6                 base    
mysql-libs.x86_64                        5.1.73-5.el6_6                 base    
mysql-server.x86_64                      5.1.73-5.el6_6                 base    
mysql-test.x86_64                        5.1.73-5.el6_6                 base    
php-mysql.x86_64                         5.3.3-46.el6_6                 updates 
qt-mysql.i686                            1:4.6.2-28.el6_5               base    
qt-mysql.x86_64                          1:4.6.2-28.el6_5               base    
rsyslog-mysql.x86_64                     5.8.10-10.el6_6                base    
rsyslog7-mysql.x86_64                    7.4.10-3.el6_7.1               updates 
View Code

 也可以使用yum -y list mysql*

[root@wulaoer ~]# yum -y list mysql*
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
 * c6-media: 
Available Packages
MySQL-python.x86_64                              1.2.3-0.3.c1.1.el6                      base
mysql.x86_64                                     5.1.73-5.el6_6                          base
mysql-bench.x86_64                               5.1.73-5.el6_6                          base
mysql-connector-java.noarch                      1:5.1.17-6.el6                          base
mysql-connector-odbc.x86_64                      5.1.5r1144-7.el6                        base
mysql-devel.i686                                 5.1.73-5.el6_6                          base
mysql-devel.x86_64                               5.1.73-5.el6_6                          base
mysql-embedded.i686                              5.1.73-5.el6_6                          base
mysql-embedded.x86_64                            5.1.73-5.el6_6                          base
mysql-embedded-devel.i686                        5.1.73-5.el6_6                          base
mysql-embedded-devel.x86_64                      5.1.73-5.el6_6                          base
mysql-libs.i686                                  5.1.73-5.el6_6                          base
mysql-libs.x86_64                                5.1.73-5.el6_6                          base
mysql-server.x86_64                              5.1.73-5.el6_6                          base
mysql-test.x86_64                                5.1.73-5.el6_6                          base
View Code

 使用yum安装mysql数据库。

[root@wulaoer ~]# yum -y install mysql-server mysql mysql-devel 

注:安装mysql只是安装了数据库,只有安装了mysql-server才相当于安装了客户端。 

 当出现Complete!的时候说明数据库安装成功了,

 设置数据库密码

[root@wulaoer ~]# mysqladmin -uroot password 'wulaoer'
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: NO)'

 注:如果没有报错,说明数据库密码修改成功了,如果有以上错误,请继续。

[root@wulaoer ~]# service mysqld stop #停止数据库
停止 mysqld:                                              [确定]
[root@wulaoer ~]# mysqld_safe --skip-grant-tables & #初始化数据库
[1] 25576
[root@wulaoer ~]# 160120 21:07:11 mysqld_safe Logging to '/var/log/mysqld.log'.
160120 21:07:11 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

[root@wulaoer ~]# mysql -uroot -p #直接进数据库不用密码
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, 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> use mysql; #切换到数据库
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> update user set password=PASSWORD("wulaoer")where user="root";#修改数据库的密码
Query OK, 3 rows affected (0.01 sec)
Rows matched: 3  Changed: 3  Warnings: 0
mysql> flush privileges;#更新权限
Query OK, 0 rows affected (0.00 sec)

mysql> quit #退出
Bye
[root@wulaoer ~]# service mysqld start
正在启动 mysqld:                                          [确定]
[root@wulaoer ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.1.73 Source distribution

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

 

本文参考http://www.linuxidc.com/Linux/2014-10/108044.htm,请尊重别人的劳动成功。

 

posted @ 2016-01-18 22:35  吴老二  阅读(649)  评论(0编辑  收藏  举报