MySQL 第一篇

1、MySQL介绍mysql

    MySQL是一个关系型数据库管理系统,由瑞典MySQL AB公司开发,目前属于Oracle公司。MySQL是一种关联数据库管理系统,关联数据库将数据保存在不一样的表中,而不是将全部数据放在一个大仓库内,这样就增长了速度并提升了灵活性linux

    特色:c++

       性能卓越,服务稳定,不多出现宕机sql

       开放源代码且无版权制约,自主性强,使用成本低数据库

       支持多操做系统,提供多种API接口,支持多种开发语言(Python,Php,Java)vim

2、MySQL安装方式安全

    1yum安装     (适合对数据库要求不过高的场合)bash

       大的门户网站把源码根据企业需求制做成rpm,搭建yum仓库tcp

    2.常规方式编译安装性能

       .configure/make/make install    (mysql 5.1及之前)

       cmake /make /make install

序号

MySQL安装方式

特色说明

1

yum/rpm安装

简单,部署速度快,可是无法定制安装,适合新手

2

二进制安装

解压软件,简单配置后就能够使用,不用安装,部署速度较快,专业DBA经常使用这种方式,软件名如:mysql-5.5.50-linux2.6-x86_64.tar.gz

3

源码编译安装

能够定制安装(指定字符集,安装路径等),可是安装时间长

4

源码软件结合yum/rpm安装

把源码软件制做成符合要求的rpm,放到yum仓库,而后经过yum来安装,结合了13的优势,安装快速,能够任意定制参数

 

3、MySQL安装实战(源码cmake方式编译安装MySQL)

    1.下载mysql/cmake安装包

1
2
3
[root@master ~] # mkdir /home/tools
[root@master ~] # wget –P /home/tools https://cmake.org/files/v2.8/cmake-2.8.12.tar.gz
[root@master ~] # wget -P /home/tools/ http://cdn.mysql.com//Downloads/MySQL-5.5/mysql-5.5.50.tar.gz

    2.创建帐号

1
2
3
4
5
6
[root@master ~] # groupadd mysql
[root@master ~] # useradd -s /sbin/nologin -g mysql -M mysql
useradd 参数说明:
    -s /sbin/nologin        # 表示禁止该用户登陆,只需角色存在便可,增强安全
    -g mysql                # 指定属组
    -M                      # 表示不建立用户家目录

    3.配置安装环境

       建立目录并受权

1
2
3
4
[root@master ~] # mkdir -p /usr/local/mysql
[root@master ~] # mkdir -p /db/mysql
[root@master ~] # chown -R mysql.mysql /usr/local/mysql
[root@master ~] # chown -R mysql.mysql /db

       安装依赖

1
[root@master ~] # yum install gcc gcc-c++ make cmake ncurses-devel bison perl -y

       配置解析

1
2
3
4
[root@master ~] # hostname
master.opsedu.com
[root@master ~] # vim /etc/hosts
192.168.10.66   master         # 添加一条

    4.安装mysql

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
[root@master tools] # tar -zxf mysql-5.5.50.tar.gz
[root@master tools] # cd mysql-5.5.50
[root@master mysql-5.5.50] # cmake \
> -DCMAKE_INSTALL_PREFIX= /usr/local/mysql/ \
> -DMYSQL_DATADIR= /db/mysql \
> -DMYSQL_TCP_PORT=3306 \
> -DDEFAULT_CHARSET=utf8 \
> -DDEFAULT_COLLATION=utf8_general_ci \
> -DEXTRA_CHARSETS=all \
> -DENABLED_LOCAL_INFILE=ON \
> -DWITH_INNOBASE_STORAGE_ENGINE=1 \
> -DWITH_FEDERATED_STORAGE_ENGINE=1 \
> -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
> -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
> -DWITHOUT_PARTITION_STORAGE_ENGINE=1 \
> -DWITH_FAST_MUTEXES=1 \
> -DWITH_ZLIB=bundled \
> -DENABLED_LOCAL_INFILE=1 \
> -DWITH_READLINE=1 \
> -DWITH_EMBEDDED_SERVER=1 \
> -DWITH_DEBUG=0 \
> -DMYSQL_UNIX_ADDR= /tmp/mysql .sock
[root@master mysql-5.5.50] # make          # 编译
[root@master mysql-5.5.50] # make install

    5.初始化mysql

       配置mysql环境变量

1
2
[root@master mysql-5.5.50] # echo 'export PATH=/usr/local/mysql/bin:$PATH' >>/etc/profile
[root@master mysql-5.5.50] # source /etc/profile

       查看配置文件

1
2
3
4
5
6
7
[root@master mysql-5.5.50] # ll support-files/*.cnf
-rw-r--r-- 1 root root  4667 Jul9 01:26 support-files /my-huge .cnf
-rw-r--r-- 1 root root 19759 Jul  9 01:26 support-files /my-innodb-heavy-4G .cnf
-rw-r--r-- 1 root root  4641 Jul9 01:26 support-files /my-large .cnf
-rw-r--r-- 1 root root  4652 Jul9 01:26 support-files /my-medium .cnf
-rw-r--r-- 1 root root  2816 Jul9 01:26 support-files /my-small .cnf
[root@master mysql-5.5.50] # /bin/cp support-files/my-small.cnf /etc/my.cnf          # copy配置文件

       建立mysql数据库文件

1
[root@master mysql-5.5.50] # /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/db/mysql --user=mysql

                  以上命令主要是生成mysql库及相关文件:

                   这些文件是mysql正确运行所必需的基本数据库文件,其功能是对mysql权限、状态等进行管理

                  

       启动mysql

1
2
3
[root@master mysql-5.5.50] # /usr/local/mysql/bin/mysqld_safe --user=mysql &
[root@master mysql-5.5.50] # netstat -lnt|grep 3306
tcp        0  0 0.0.0.0:3306          0.0.0.0:*             LISTEN

       配置mysql开机启动

1
2
3
4
[root@master mysql-5.5.50] # cp support-files/mysql.server /etc/init.d/mysqld
[root@master mysql-5.5.50] # chmod 700 /etc/init.d/mysqld
[root@master mysql-5.5.50] # chkconfig --add mysqld
[root@master mysql-5.5.50] # chkconfig mysqld on

       初始化碰见错误

           示例1:

           WARING:The host ‘mysql’ could not be locked up with resolveip

           须要修改主机名的解析,使其和usernae –n同样

          

           示例2:

           ERROR:1004 Can’t create file /tmp/#sql300e_1_0.frm(errno:13)

           缘由是/tmp权限有问题(不解决,后面可能没法登录数据库)

          

    6.后续操做

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@master mysql-5.5.50] # mysql       # mysql安装好后,默认没有密码
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.50 Source distribution
  
Copyright (c) 2000, 2016, 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增长(设定)密码
[root@master mysql-5.5.50] # mysqladmin -uroot password 'q.123456'

      7. 单实例MySQL自动部署脚本

相关文章
相关标签/搜索