首页 > 数据库 > MySQL > 正文

Linux下安装mysql的方式(yum和源码编译两种方式)

2024-07-24 12:50:39
字体:
来源:转载
供稿:网友

这里介绍Linux下两种安装mysql的方式:yum安装和源码编译安装。

1. yum安装

(1)首先查看centos自带的mysql是否被安装:

# yum list installed |grep mysql //若有自带安装的mysql,将其卸载# yum -y remove mysql-libs.x86_64

(2)下载MySQL官网的yum仓库:https://dev.mysql.com/downloads/repo/yum/,


# yum localinstall mysql57-community-release-el6-11.noarch.rpm//查看yum仓库是否成功添加# yum repolist enabled |grep "mysql.*-community.*"

(3)使用mysql yum仓库时,默认情况下选择的最新版本进行安装,也可以通过手动编辑文件来选择一个版本安装。例如,要安装mysql5.6版本,则再mysql56-community设置enabled=1,mysql57-community设置enabled=0。

# vim /etc/yum.repos.d/mysql-community.repo[mysql57-community]name=MySQL 5.7 Community Serverbaseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/enabled=0gpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql# Enable to use MySQL 5.6[mysql56-community]name=MySQL 5.6 Community Serverbaseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/6/$basearch/enabled=1gpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

(4)安装mysql

# yum install mysql-community-server

(5)启动mysql服务

# service mysqld start

若出现下面输出则表示mysql安装成功:

Starting mysqld:[ OK ]

2. 源码编译安装mysql

(1)首先安装源码编译所需要的包

# yum -y install make gcc-c++ cmake bison-devel ncurses-devel

(2)下载并解压安装包

# wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.14.tar.gz
# tar xvf mysql-5.6.14.tar.gz

(3)编译安装(编译参数按实际情况制定)

# cd mysql-5.6.14# cmake .-DCMAKE_INSTALL_PREFIX=/usr/local/mysql /-DMYSQL_DATADIR=/usr/local/mysql/data /-DSYSCONFDIR=/etc /-DWITH_MYISAM_STORAGE_ENGINE=1 /-DWITH_INNOBASE_STORAGE_ENGINE=1 /-DWITH_MEMORY_STORAGE_ENGINE=1 /-DWITH_READLINE=1 /-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock /-DMYSQL_TCP_PORT=3306 /-DENABLED_LOCAL_INFILE=1 /-DWITH_PARTITION_STORAGE_ENGINE=1 /-DEXTRA_CHARSETS=all /-DDEFAULT_CHARSET=utf8 /-DDEFAULT_COLLATION=utf8_general_ci# make && make install

(4)配置mysql

  设置权限:

# useradd mysql# passwd mysql # chown -R mysql:mysql /usr/local/mysql

  初始化mysql:

# cd /usr/local/mysql# scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql

注意:在/etc目录下会存在一个my.cnf,需要将此文件更名为其他的名字,如:/etc/my.cnf.bak,否则,该文件会干扰源码安装的MySQL的正确配置,造成无法启动。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表