mysql5.6安装成功测试_软件测试环境的搭建系列:[2] MySQL数据库的安装

本文介绍CentOS系统上用源码包方式安装MySQL的方法,源码安装方式是需要自己到网上下载源码包,然后解压安装,此方式可以指定配置参数,更加灵活方便,兼容性更强。

环境:CentOS 7.6+MySQL5.6

1. 安装编译源码所需的工具和库

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

[root@centos75 ~]# yum -y groupinstall "Development tools" "Desktop Platform Development" "Server Platform Development"

[root@centos75 ~]# yum -y install cmake

[root@centos75 ~]# yum -y install openssl openssl-devel ncurses ncurses-devel

2. 删除系统自带的MySQL

[root@centos75 ~]# rpm -qa | grep mariadb

[root@centos75 ~]# yum -y remove mari*

[root@centos75 ~]# rm -rf /var/lib/mysql/*

[root@centos75 ~]# rpm -qa | grep mariadb

3. 创建数据库目录、mysql用户,并修改数据目录的属主

[root@centos75 ~]# mkdir -pv /mydata/data

[root@centos75 ~]# useradd -s /sbin/nologin mysql

[root@centos75 ~]# chown -R mysql:mysql /mydata/data/

4. 下载MySQL源码tar包解压

[root@centos75 ~]# cd /usr/local/src

[root@centos75 src]# wget https://cdn.mysql.com//archives/mysql-5.6/mysql-5.6.37.tar.gz --no-check-certificate

[root@centos75 src]# tar -zxvf mysql-5.6.37.tar.gz -C /usr/local/

5. 设置编译参数,编译,安装

[root@centos75 src]# cd /usr/local/mysql-5.6.37

[root@centos75 mysql-5.6.37]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/mydata/data/ -DSYSCONFDIR=/etc -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_SSL=system -DWITH_ZLIB=system -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci

[root@centos75 mysql-5.6.37]# make

[root@centos75 mysql-5.6.37]# make install

6. 初始化数据库

[root@centos75 mysql-5.6.37]# cd /usr/local/mysql/scripts/

[root@centos75 scripts]#./mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/mydata/data/

7. 复制MySQL服务启动脚本

[root@centos75 scripts]# cd /usr/local/mysql/support-files/

[root@centos75 support-files]# cp mysql.server /etc/init.d/mysqld

[root@centos75 support-files]# chmod a+x /etc/init.d/mysqld

8. 配置MySQL环境变量

[root@centos65 ~]# vi /etc/profile

在/etc/profile文件末尾添加如下两行

export PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH

添加完成后退出编辑,执行如下命令使配置生效

[root@centos75 ~]# source /etc/profile

9. 复制MySQL配置文件

[root@centos75 ~]# cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf

在my.cnf文件中增加如下配置,添加到[mysqld]之后:

[root@centos75 ~]# vi /etc/my.cnf

innodb_file_per_table = 1

datadir = /mydata/data

port = 3306

user = mysql

server_id = 1

socket = /tmp/mysql.sock

添加后的文件内容应该如下所示。

10. 启动MySQL服务

[root@centos75 ~]# service mysqld start

执行如下命令查看MySQL服务是否正常运行,显示is running...表示正在运行。

[root@centos75 ~]# service mysqld status

SUCCESS! MySQL running (1350)

11. 设置数据库的root用户密码

[root@centos75 bin]# /usr/local/mysql/bin/mysql_secure_installation

备注:安装后MySQL的默认密码为空,所以在输入当前密码时直接回车即可。

12. 设置MySQL服务开机自启动

添加MySQL到开机自启动服务

[root@localhost ~]# chkconfig --add mysqld

设置MySQL服务开机自启动

[root@localhost ~]# chkconfig mysqld on

查看是否设置成功,执行如下命令查询,如果显示结果与以下结果一致,表示已完成设置开机自启动MySQL

[root@localhost ~]# chkconfig --list | grep mysqld

mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off

13. 连接数据库

[root@centos65 bin]# mysql -uroot -p密码

Warning: Using a password on the command lineinterface can be insecure.

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

Your MySQL connection id is 17

Server version: 5.6.37 Source distribution

Copyright (c) 2000, 2017, Oracle and/or itsaffiliates. All rights reserved.

Oracle is a registered trademark of OracleCorporation and/or its

affiliates. Other names may be trademarks of theirrespective

owners.

Type 'help;' or '\h' for help. Type '\c' to clearthe current input statement.

mysql>

备注:这里登录密码是前面设置的root用户密码

到这里,就完成了源码方式安装MySQL。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值