Mysql简单部署讲析

发布时间:2020-04-27 14:05:02 作者:三月
来源:亿速云 阅读:298

本文主要给大家介绍Mysql简单部署讲析,希望可以给大家补充和更新些知识,如有其它问题需要了解的可以持续在亿速云行业资讯里面关注我的更新文章的。

MySQL是一个关系型数据库管理系统,由瑞典MySQL AB公司开发,目前属于Oracle公司。MySQL所使用的SQL语言是用于访问数据库的最常用标准化语言。由于其体积小、速度快、总体拥有成本低,尤其是开放源码这一特点,一般中小型网站的开发都选择MySQL作为网站数据库。由于其社区版的性能卓越,搭配PHPApache可组成良好的开发环境。本篇将为大家讲解mysql的简单部署。

mysql的分为四个版本:

并且mysql为了更好发展将版本路线分为了三条。

由于mysql不用产品线之间的编译安装方法还是有差别,因此本篇将分别为大家讲解mysql5.1.7版本和5.6.13版本的简单部署。

 Mysql简单部署讲析


5.1.7版本

 

 

一、准备工作

1、开发环境部署

[root@c64web ~]# yum groupinstall "Development tools" "Server Platform Development" -y #安装这两个开发环境的软件包组

[root@c64-web ~]# yum install pcre* -y #安装pcre兼容的正则表达式

2、创建用户及目录

[root@c64-web ~]# useradd -s /sbin/nologin -M mysql #创建mysql用户,并加入mysql组,不创建家目录,关闭登陆

[root@c64-web ~]# mkdir /mydata  #创建数据库存放目录

[root@c64-web ~]# chown -R mysql.mysql /mydata

3、下载源码包

[root@c64-web ~]# cd /server/tools

[root@c64-web tools]# wget http://mysql.ntu.edu.tw/Downloads/MySQL-5.1/mysql-5.1.70.tar.gz

二、编译安装

准备工作已经做好了,现在我们就开始编译安装mysql

[root@c64-web tools]# tar zxf mysql-5.1.70.tar.gz

[root@c64-web tools]# cd mysql-5.1.70

[root@c64-web mysql-5.1.70]# ./configure \

--prefix=/usr/local/mysql \     #设定mysql安装路径,默认为/usr/local

--with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock \  #指定Mysql socket文件存放目录

--localstatedir=/mydata \       #设定mysql的数据文件存放位置

--enable-assembler \            #允许使用汇编模式(优化性能)

--enable-thread-safe-client \   #以线程方式编译客户端

--with-mysqld-user=mysql \      #指定MySQL运行的系统用户

--with-big-tables \             #启用大表支持

--without-debug \               #使用非debug模式

--with-pthread \                #强制使用pthread线程序库编译

--with-extra-charsets=complex \ #复杂字符集支持

--with-readline \               #使用系统readline代替捆绑副本。

--with-ssl \                    #启用ssl加密

--with-embedded-server \        #构建嵌入式MySQL (libmysqld.a)

--enable-local-infile \         #mysql支持从本地加载数据库(默认关闭)

--with-plugins=partition        #mysql分区功能支持

--with-plugins=innobase \       #innobas存储引擎支持

--with-mysqld-ldflags=-all-static \    #云服务器使用静态库(优化性能)

--with-client-ldflags=-all-static      #客户端使用静态库(优化性能)

[root@c64-web mysql-5.1.70]# make && make install

执行了上面的操作之后,mysql-5.1.7版本就编译安装成功了。

下面为快速复制,编译配置文本:

[root@c64-web mysql-5.1.70]#./configure --prefix=/usr/local/mysql-5.1.70--with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock  --localstatedir=/mydata --enable-assembler--enable-thread-safe-client --with-mysqld-user=mysql --with-big-tables --without-debug--with-pthread --with-extra-charsets=complex --with-readline --with-ssl--with-embedded-server --enable-local-infile --with-plugins=partition --with-plugins=innobase --with-mysqld-ldflags=-all-static--with-client-ldflags=-all-static

1、创建目录软链接

mysql安装完成之后,我们要先为编译安装好的目录添加软链接。此操作在生产环境中为重要调优参数,添加这条软链接的目的有两点:1、方便人类使用。2、便于以后升级版本。

[root@c64-web mysql-5.1.70]# cd /root

[root@c64-web ~]# ln -s /usr/local/mysql-5.1.70 /usr/local/mysql

2、创建其它相应目录及权限设置

[root@c64-web ~]# mkdir /mydata   #建立mysql数据文件目录

[root@c64-web ~]# chown -R mysql /mydata  #授权mysql用户访问mysql数据库目录

3、获取Mysql主配置文件并修改

由于mysql的主配置文件,编译安装之后默认是没有的。因此我们需要在mysql的编译包中,选择预支的*.cnf结尾的配置文件将其复制到我们的/etc/录下。

[root@c64-web ~]# ll /server/tools/mysql-5.1.70/support-files/*.cnf

-rw-r--r-- 1 root root 4714 11月 6 02:25 /server/tools/mysql-5.1.70/support-files/my-huge.cnf

-rw-r--r-- 1 root root 19763 11月 6 02:25 /server/tools/mysql-5.1.70/support-files/my-innodb-heavy-4G.cnf

-rw-r--r-- 1 root root 4688 11月 6 02:25 /server/tools/mysql-5.1.70/support-files/my-large.cnf

-rw-r--r-- 1 root root 4699 11月 6 02:25 /server/tools/mysql-5.1.70/support-files/my-medium.cnf

-rw-r--r-- 1 root root 2467 11月 6 02:25 /server/tools/mysql-5.1.70/support-files/my-small.cnf  #中小型公司用这个即可

[root@c64-web mysql-5.1.70]# /bin/cp /server/tools/mysql-5.1.70/support-files/my-small.cnf /etc/my.cnf

修改mysql的主配置文件/etc/my.cnf,添加如下1行

datadir=/mydata  #我们自定义的数据库存放目录

4、让系统识别源码包安装的软件

a)将mysql的库文件路径加入系统的库文件搜索路径中

方法一:直接做软链接

[root@c64-web ~]# ln -s /usr/local/mysql/lib/mysql   /usr/lib/mysql

方法二:利用ldconfig导入系统库(推荐)

[root@c64web ~]# echo "/usr/local/mysql/lib" >> /etc/ld.so.conf.d/mysql.conf

[root@c64-web ~]# ldconfig

b)输出mysql的头文件到系统头文件

[root@c64web ~]# ln –

s /usr/local/mysql/include/mysql /usr/include/mysql

c)配置mysql命令全局使用路径

[root@c64web ~]# echo "PATH=/usr/local/mysql/bin:$PATH" >>/etc/profile

[root@c64-web ~]# source /etc/profil

5、以mysql用户的身份初始化数据库并启动

[root@c64-web ~]# /usr/local/mysql/bin/mysql_install_db --basedir=/usr/local/mysql --datadir=/mydata --user=mysql  #初始化mysql数据库文件

WARNING: The host 'c64-web' could not be looked up with resolveip.

This probably means that your libc libraries are not 100 % compatible

with this binary MySQL version. The MySQL daemon, mysqld, should work

normally with the exception that host name resolving will not work.

This means that you should use IP addresses instead of hostnames

when specifying MySQL privileges !   #此警告我们可以通过在/etc/hosts文件中修改127.0.0.1后面的localhost为当前c64-web来消除。

Installing MySQL system tables...

131108 18:07:26 [Warning] '--skip-locking' is deprecated and will be removed in a future release. Please use '--skip-external-locking' instead.   #这里的警告无需理会

OK

Filling help tables...

131108 18:07:27 [Warning] '--skip-locking' is deprecated and will be removed in a future release. Please use '--skip-external-locking' instead.   #这里的警告无需理会

OK

To start mysqld at boot time you have to copy

support-files/mysql.server to the right place for your system

#这里是说,你可以创建快速启动脚本,我们下面会提到

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !

To do so, start the server, then issue the following commands:

/usr/local/mysql/bin/mysqladmin -u root password 'new-password'

/usr/local/mysql/bin/mysqladmin -u root -h lhh password 'new-password'

#教你如何创建root用户进入mysql数据库的密码

Alternatively you can run:

/usr/local/mysql/bin/mysql_secure_installation

which will also give you the option of removing the test

databases and anonymous user created by default.  This is

strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:

cd /usr/local/mysql ; /usr/local/mysql/bin/mysqld_safe &

#上面的即为开启命令中的一种,后面的&为放入后台执行的意思

You can test the MySQL daemon with mysql-test-run.pl

cd /usr/local/mysql/mysql-test ; perl mysql-test-run.pl

#这里是给你说如何执行测试

Please report any problems with the /usr/local/mysql/scripts/mysqlbug script!

#以上为初始化创建mysql数据库文件时产生的信息。

[root@lhh mydata]# cd /usr/local/mysql ; /usr/local/mysql/bin/mysqld_safe &

[1] 7146

131108 18:50:37 mysqld_safe Logging to '/mydata/lhh.err'.

131108 18:50:37 mysqld_safe Starting mysqld daemon with databases from /mydata   #此处需要敲击回车才能回到命令输入界面。

mysql数据库启动的另外一种方法

[root@c64-web ~]# /bin/cp /server/tools/mysql-5.1.70/support-files/mysql.server /etc/init.d/mysqld    #拷贝mysql启动脚本mysql命令路径

[root@c64-web ~]# chmod 700 /etc/init.d/mysqld      #使脚本可执行

[root@c64-web ~]# /etc/init.d/mysqld start    #这是启动数据库方法之一

[root@c64-web ~]# /etc/init.d/mysqld stop     #关闭数据库的方法

[root@c64-web ~]# killalll mysqld #关闭数据库的另外一种方法

6、检查mysql数据库是否启动:

[root@c64-web ~]# netstat -lnt|grep 3306

tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN

可以看到,我们的mysql服务已经启动起来了。这里如果发现3306端口没起来,请tail -100 /usr/local/mysql/data/机器名.err 检查日志报错进行调试。

7、设置初始账户,并登陆后台

在上面,初始化创建mysql数据库的时候,已经给我们提到了如何给mysql数据库账号设置密码,下面我们就进行操作。

[root@c64-web ~]# mysqladmin -u root password 123456   #设置密码

[root@c64-web ~]# history -c  #设置之后注意清除历史记录,防止密码泄露

[root@c64-web ~]# mysql -u root -p    #连接数据库查看

Enter password:   #这里输入刚才设置的密码

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 2

Server version: 5.1.70 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> show databases;   #查看现有的数据库

+--------------------+

| Database |

+--------------------+

| information_schema |

| mysql |

| test |

+--------------------+

3 rows in set (0.00 sec)

mysql> select user();    #查看现有用户

+----------------+

| user() |

+----------------+

| root@localhost |

+----------------+

1 row in set (0.00 sec)

mysql> quit   #退出

Bye

到此,我们mysql-5.1.17的部署就已经完成了,下面将是5.6.13的部署。

 

 

5.6.13版本

mysql的第二条产品线和第一条产品线的产品主要在数据存储引擎和编译安装的方法上有点区别,因此这里我就主要对编译安装的部分进行讲解,其它地方都是大同小异的。

mysql-5.6.13源码包下载地址:http://mysql.ntu.edu.tw/Downloads/MySQL-5.6/mysql-5.6.13.tar.gz

一、更改编译配置工具为cmake

注意下面mysql-5.6.x系列版本在编译配置时,放弃了用./configure,进而使用到了cmake,因此我们需要先安装cmake这个工具,下面才能执行编译配置。

二、编译参数更改

mysql-5.6.x系列版本综合性的编译参数详解:

[root@c64-web mysql-5.6.13]# cmake

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \          #指定mysql安装目

-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \                #Unix socket文件路径,自定义此路径防报错

-DDEFAULT_CHARSET=gbk \                            #默认字符

-DDEFAULT_COLLATION=gbk_chinese_ci \               #校验字符

-DEXTRA_CHARSETS=all \                             #安装所有扩展字符集

-DWITH_MYISAM_STORAGE_ENGINE=1 \                   #安装myisam存储引擎

-DWITH_INNOBASE_STORAGE_ENGINE=1 \                 #安装innodb存储引擎

-DWITH_ARCHIVE_STORAGE_ENGINE=1 \                  #安装archive存储引擎

-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \                #安装blackhole存储引擎

-DWITH_MEMORY_STORAGE_ENGINE=1 \                   #安装memory存储引擎

-DWITH_FEDERATED_STORAGE_ENGINE=1                  #安装frderated存储引擎

-DWITH_READLINE=1 \                                #快捷键功能

-DENABLED_LOCAL_INFILE=1 \                         #允许从本地导入数据

-DMYSQL_DATADIR=/usr/local/mysql/data \            #数据库存放目录

-DMYSQL_USER=mysql \                               #数据库属主

-DMYSQL_TCP_PORT=3306 \                            #数据库端口

-DSYSCONFDIR=/etc \                                #MySQL配辑文件

-DWITH_SSL=yes                                     #数据库SSL

下面为快捷复制执行命令:

[root@c64-web  mysql-5.6.13]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql  -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=gbk  -DDEFAULT_COLLATION=gbk_chinese_ci -DEXTRA_CHARSETS=all  -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1  -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1  -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_READLINE=1  -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/mydata -DMYSQL_USER=mysql  -DMYSQL_TCP_PORT=3306 -DSYSCONFDIR=/etc -DWITH_SSL=yes

执行之后,还是用make&&make install 来执行编译安装。

三、主配置文件调整

5.6.X系列的版本中,mysql的主配置文件发生了变化。可以看到,mysql-5.6.13版本中取消了原来的my-huge.cnfmy-large.cnfmy-small.cnf模版,同时取而代之是my.cnf 或者是my-default.cnf一个配置模板。

[root@c64-web mysql-5.6.13]# ll /server/tools/mysql-5.6.13/support-files/*.cnf

-rw-r--r--. 1 root root 1126 Nov  8 01:37 /server/tools/mysql-5.6.13/support-files/my-default.cnf

[root@c64-web mysql-5.6.13]# /bin/cp /server/tools/mysql-5.6.13/support-files/my-default.cnf /etc/my.cnf

并且,模板文件里需要配置的地方很少。这是因为mysql-5.6.x系列将以前许多默认值设置不合理的参数都进行了调整,并且采用了一种out-of-box的思维,即有些值是固定的,有些值是启动时,根据其他参数或者服务器的配置来自动设置的,所以不需要初始指定很多值。

 看了以上关于Mysql简单部署讲析,希望能给大家在实际运用中带来一定的帮助。本文由于篇幅有限,难免会有不足和需要补充的地方,如有需要更加专业的解答,可在官网联系我们的24小时售前售后,随时帮您解答问题的。


 

 

 

 


推荐阅读:
  1. 部署Istio实现双向TLS迁移讲析
  2. 配置yum及安装mysql讲析

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

mysql

上一篇:mysql数据库完整备份和增量备份脚本讲义

下一篇:测试演练系统DVWA流程

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》