mysql5.6安装成功测试_软件测试环境的搭建系列:[2] 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。

文章知识点与官方知识档案匹配,可进一步学习相关知识MySQL入门技能树使用数据库 创建和删除数据库32320 人正在系统学习中 相关资源:汽轮机仿真软件.zip-机器学习工具类资源-CSDN文库

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2021年1月22日
下一篇 2021年1月22日

相关推荐