MySql教程

mysql 安装_源码编译安装mysql_rpm安装mysql

本文主要是介绍mysql 安装_源码编译安装mysql_rpm安装mysql,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

 
参考视频教程:  
 **高并发 高性能 高可用 MySQL 实战  **
不同mysql版本的安装方法(mysql 5.1,mysql 5.6),rpm安装mysql,源码编译安装mysql

在linux下,mysql 安装可以分为,通过预编译rpm或者src.rpm安装(redhat linux或者centos下),源码安装(tar.gz).
这里讲解的mysql安装都是在:centos 6.4和redhat 6.4下进行的,centos是本站提供的无人职守安装ISO哦下测试的
一:rpm安装mysql
1.1 通过yum安装mysql
1.2 通过rpm安装mysql
二:mysql5.5之前版本的源码编译安装
2.1 不带google-perftool编译的mysql安装
2.2 带google-perftool编译的mysql安装
三:mysql5.5之后版本的源码编译安装
3.1 不内置memcached的mysql5.6安装
3.2 内置memcached的mysql5.6安装
一:mysql安装-rpm安装mysql
1.通过yum安装mysql,版本相对比较低,还是mysql-server-5.1.69呢,想要安装高点的版本就从源码安装mysql吧
[root@www.linuxshizhan.com ~]# yum -y install mysql mysql-server
Total download size: 10 M
Installed size: 29 M
Downloading Packages:
(1/4): mysql-5.1.69-1.el6_4.x86_64.rpm | 907 kB 00:00
(2/4): mysql-server-5.1.69-1.el6_4.x86_64.rpm | 8.7 MB 00:07
(3/4): perl-DBD-MySQL-4.013-3.el6.x86_64.rpm | 134 kB 00:00
(4/4): perl-DBI-1.609-4.el6.x86_64.rpm | 705 kB 00:00

Total 1.1 MB/s | 10 MB 00:09
2.配置mysql,从模板配置文件中拷贝一个
[root@www.linuxshizhan.com ~]# scp /usr/share/mysql/my-large.cnf /etc/my.cnf
3.初始化mysql

初始mysql基本数据库

[root@www.linuxshizhan.com ~]# mysql_install_db –user=mysql

启动mysql

[root@www.linuxshizhan.com ~]#service mysqld start

初始化mysql默认超级用户root的密码为123456

[root@www.linuxshizhan.com ~]# /usr/bin/mysqladmin -u root password ‘123456’
通过rpm安装mysql就整完了,是不是非常的简单?
二:下载最新版本的mysql rpm,通过rpm -ivh 安装,这种方式存在安装不成功的风险(跟linux版本有很大关系),建议直接通过yum安装
由于是centos6.4 我这里下载了,当前的最新版本。
MySQL-server-5.6.13-1.el6.x86_64.rpm
[root@www.linuxshizhan.com ~]# rpm -ivh MySQL-server-5.6.13-1.el6.x86_64.rpm
三:mysql源码编译安装mysql-5.1.71
3.1 mysql下载,源码
http://cdn.mysql.com/Downloads/MySQL-5.1/mysql-5.1.71.tar.gz
3.2 建立mysql用户,不带shell哦
useradd -M -s /sbin/nologin mysql
3.3 mysql源码解压
tar xvf mysql-5.1.71.tar.gz
3.4 mysql源码编译安装
[root@www.linuxshizhan.com ~]# cd mysql-5.1.71

如果使用不采用google-perftool安装 ,最优化安装,google-perftool是什么,自己google一下

[root@www.linuxshizhan.com ~]# ./configure –prefix=/usr/local/mysql \
–with-mysqld-user=mysql \
–with-unix-socket-path=/tmp/mysql.sock \
–localstatedir=/usr/local/mysql/var \
–with-tcp-port=3306 \
–without-debug –enable-assembler \
–sysconfdir=/etc \
–with-mysqld-user=mysql \
–with-charset=utf8 \
–with-collation=utf8_general_ci \
–with-extra-charsets=gbk,utf8 \
–with-client-ldflags=-all-static \
–with-mysqld-ldflags=-all-static \
–with-pthread \
–enable-thread-safe-client \
–with-big-tables \
–with-plugins=all

采用google-perftool安装 ,最优化编译安装

采用google-perftool,不能使用–with-mysqld-ldflags=-all-static,否则GOOGLE的TCMALL.SO库加载不进来

./configure –prefix=/usr/local/mysql \
–with-mysqld-user=mysql \
–with-unix-socket-path=/tmp/mysql.sock \
–localstatedir=/usr/local/mysql/var \
–with-tcp-port=3306 \
–without-debug –enable-assembler \
–sysconfdir=/etc \
–with-mysqld-user=mysql \
–with-charset=utf8 \
–with-collation=utf8_general_ci \
–with-extra-charsets=gbk,utf8 \
–with-pthread \
–enable-thread-safe-client \
–with-big-tables \
–with-plugins=all
3.5 安装
make;make install
3.6 配置mysql,从模板配置文件中拷贝一个
[root@www.linuxshizhan.com ~]# scp /usr/local/mysql/share/mysql/my-medium.cnf /etc/my.cnf
3.7 初始化mysql

初始mysql基本数据库

[root@www.linuxshizhan.com ~]# /usr/local/mysql/bin/mysql_install_db –user=mysql

拷贝重启脚本到开机启动

[root@www.linuxshizhan.com ~]# scp /usr/local/mysql/share/mysql/mysql.server /etc/init.d/mysqld

将mysql加入自动启动

[root@www.linuxshizhan.com ~]# chmod 711 /etc/init.d/mysqld
[root@www.linuxshizhan.com ~]# chown mysql:mysql /etc/init.d/mysqld
[root@www.linuxshizhan.com ~]# chkconfig -add mysqld
[root@www.linuxshizhan.com ~]# chkconfig –level 35 mysqld on
++++++++++++++++++++++++++++++++++++++++++++++++++++++++

如果是把Google perftool编译进去了,在启动前。需以下操作,必须的哦

启用Google perftool

也可以通过export LD_PRELOAD=/usr/local/lib/libtcmalloc.so加入perftool(不推荐),但其他方式好像加入不成功

使mysql使用google-perftool修改mysql启动脚本

vi /usr/local/mysql/bin/mysqld_safe

在第一行增加一行,并注释掉executing mysqld_safe这句

++++++++++++++++++++++++++++++++++++++++++++++++++++++++

启动mysql

[root@www.linuxshizhan.com ~]#service mysqld start

初始化mysql默认超级用户root的密码为123456

[root@www.linuxshizhan.com ~]# /usr/bin/mysqladmin -u root password ‘123456’
好了,mysql5.1.7的源码编译安装就介绍到这里啊
四:mysql源码编译安装mysql5.5.6.13 ,我们知道mysql5.5之后的版本源码编译是通过cmake编译啦。
4.1 mysql5.5.6.13下载:
http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.13.tar.gz
4.2 建立mysql用户,不带shell哦
[root@www.linuxshizhan.com ~]# useradd -M -s /sbin/nologin mysql
4.3 安装cmake
[root@www.linuxshizhan.com ~]# yum -y install cmake
4.4 mysql5.5.6.13源码解压
[root@www.linuxshizhan.com ~]# tar xvf mysql-5.5.6.13.tar.gz
4.5 mysql5.5.6.13编译
[root@www.linuxshizhan.com ~]# cd mysql-5.5.6.13
[root@www.linuxshizhan.com ~]# cmake . -DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_TCP_PORT=3306 \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DENABLED_LOCAL_INFILE=ON \
-DWITH_EXTRA_CHARSETS=complex \
-DENABLE_DEBUG_SYNC=OFF \
-DWITH_ZLIB=bundled \
-DINSTALL_LAYOUT=STANDALONE \
-DENABLED_PROFILING=ON \
-DMYSQL_MAINTAINER_MODE=OFF \
-DWITH_DEBUG=OFF
[root@www.linuxshizhan.com ~]# make;make install
4.6 初始化mysql
[root@www.linuxshizhan.com ~]# cat > /etc/ld.so.conf.d/libmysql.conf <<EOF
/usr/local/mysql/lib/
EOF
ldconfig
}

初始mysql基本数据库

[root@www.linuxshizhan.com ~]# cd /usr/local/mysql/
[root@www.linuxshizhan.com ~]# scripts/mysql_install_db –user=mysql
[root@www.linuxshizhan.com ~]# chown -R mysql:mysql /usr/local/mysql
[root@www.linuxshizhan.com ~]# /usr/local/mysql/bin/mysqld_safe &

拷贝重启脚本到开机启动

[root@www.linuxshizhan.com ~]# scp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

将mysql加入自动启动

[root@www.linuxshizhan.com ~]# chmod 711 /etc/init.d/mysqld
[root@www.linuxshizhan.com ~]# chkconfig –add mysqld
[root@www.linuxshizhan.com ~]# chkconfig –level 35 mysqld on

启动mysql

[root@www.linuxshizhan.com ~]#service mysqld start

初始化mysql默认超级用户root的密码为123456

[root@www.linuxshizhan.com ~]# /usr/bin/mysqladmin -u root password ‘123456’
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
现在mysql5.6已经内置了memcached,如果要开启memcached话
就在上面的编译参数中加入-DWITH_INNODB_MEMCACHED=1 这一行即可。
如下,其他均一样
cmake . -DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DENABLED_LOCAL_INFILE=ON \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_TCP_PORT=3306 \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=complex \
-DENABLE_DEBUG_SYNC=OFF \
-DWITH_ZLIB=bundled \
-DINSTALL_LAYOUT=STANDALONE \
-DENABLED_PROFILING=ON \
-DMYSQL_MAINTAINER_MODE=OFF \
-DWITH_INNODB_MEMCACHED=1 \
-DENABLE_GPROF=1 \
-DWITH_DEBUG=OFF
make
make install
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
好了。linux下mysql 安装就介绍到这里,各个版本的mysql安装均已经触及,linux系统实战接下来将介绍mysql命令

  • 本文链接:http://www.linuxshizhan.com/mysql/mysql_install.html
这篇关于mysql 安装_源码编译安装mysql_rpm安装mysql的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!