欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

centos源码安装MySQL-5.6数据库

程序员文章站 2022-03-03 14:34:18
...

创建源码放置目录进入源码放置目录

[[email protected] ~]# mkdir /tools
[[email protected] ~]# cd /tools/

创建mysql用户名和组

[[email protected] mysql-5.6.41]# groupadd mysql
[[email protected] mysql-5.6.41]# useradd -M mysql -g mysql -s /sbin/nologin

安装依赖软件

[[email protected] tools]# yum -y install ncurses-devel cmake bison gcc gcc-c++ libaio ncurses autoconf

下载源码包,最小化安装的centos中的wget命令需要提前下载

[[email protected] tools]# wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.41.tar.gz

[[email protected] tools]# ls
mysql-5.6.41.tar.gz

解压源码包,进到MySQL源码安装目录

[[email protected] tools]# tar -xvf mysql-5.6.41.tar.gz

... ...

[[email protected] tools]# cd mysql-5.6.41/
[[email protected] mysql-5.6.41]# ls
BUILD           cmd-line-utils   dbug                 include   libmysqld    mysys      README   sql-bench   support-files  vio
client          config.h.cmake   Docs                 INSTALL   libservices  mysys_ssl  regex    sql-common  tests          win
cmake           configure.cmake  Doxyfile-perfschema  libevent  man          packaging  scripts  storage     unittest       zlib
CMakeLists.txt  COPYING          extra                libmysql  mysql-test   plugin     sql      strings     VERSION

编译数据库生成编译文件

[[email protected] mysql-5.6.41]# cmake -DMYSQL_USER=mysql  -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/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=/data/mysql/mysqld.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

编译参数说明

-DMYSQL_USER=mysql  # 指定用户

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql  # 安装路径

-DMYSQL_DATADIR=/data/mysql/data  # 数据存放位置

-DSYSCONFDIR=/etc # my.cnf位置

-DWITH_MYISAM_STORAGE_ENGINE=1  # 支持MyIASM引擎

-DWITH_INNOBASE_STORAGE_ENGINE=1  # 支持InnoDB引擎

-DWITH_MEMORY_STORAGE_ENGINE=1  # 支持Menmory引擎

-DWITH_READLINE=1  # 快捷键功能

-DMYSQL_UNIX_ADDR=/data/mysql/mysqld.sock  # 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

查看是否生成编译文件,如果没有删除CMakeCache.txt文件重新编译

[[email protected] mysql-5.6.41]# ls Makefile
Makefile

编译并安装,编译时时间比较久

[[email protected] mysql-5.6.41]# make && make install

[[email protected] mysql-5.6.41]# mkdir -p /data/mysql/data
[[email protected] mysql-5.6.41]# cd /usr/local/mysql/

[[email protected] mysql]# setfacl -m u:mysql:rwx -R /data/mysql/
[[email protected] mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql/data

[[email protected] mysql]# ls /data/mysql/data/
ibdata1  ib_logfile0  ib_logfile1  mysql  performance_schema  test

[[email protected] mysql]# \cp -r support-files/my-default.cnf /etc/my.cnf
[[email protected] mysql]# vim /etc/my.cnf

[client]
port = 3306
default-character-set = utf8
socket = /data/mysql/mysqld.sock

[mysqld]
basedir = /usr/local/mysql
datadir = /data/mysql/data
port = 3306
socket = /data/mysql/mysqld.sock
default-storage-engine  = INNODB
character-set-server    = utf8
pid-file                = /data/mysql/mysqld.pid

拷贝系统服务文件到系统目录

[[email protected] mysql]# cp support-files/mysql.server /etc/init.d/mysqld

授权数据库安装目录,启动数据库。

[[email protected] mysql]# setfacl -m u:mysql:rwx -R /usr/local/mysql/
[[email protected] mysql]# /etc/init.d/mysqld start
Starting MySQL.Logging to '/data/mysql/data/mysql.err'.
 SUCCESS!
[[email protected] mysql]# netstat -nutpl|grep 3306
tcp6       0      0 :::3306                 :::*                    LISTEN      16891/mysqld        

配置环境变量

[[email protected] mysql]# vim /etc/profile

# mysql
export MYSQL_HOME=/usr/local/mysql
export PATH=$PATH:$MYSQL_HOME/bin

[[email protected] mysql]# source /etc/profile

进入数据库

[[email protected] mysql]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.41 Source distribution

Copyright (c) 2000, 2018, 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              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)

设置数据库密码

[[email protected] mysql]# mysqladmin -uroot password 123456