当前位置: 移动技术网 > IT编程>数据库>Mysql > mySQL的安装过程---二进制和源码安装

mySQL的安装过程---二进制和源码安装

2019年11月02日  | 移动技术网IT编程  | 我要评论

安装 mysql


源码包安装


优化基础源

[root@db03 ~]# vim /etc/yum.repos.d/centos-base.repo 

安装依赖包

[root@db03 ~]# yum install -y cmake ncurses-devel autoconf

下载(或者上传):

wget https://downloads.mysql.com/archives/get/file/mysql-5.6.44.tar.gz

解压:

[root@db03 ~]# tar xf mysql-5.6.44.tar.gz 
[root@db03 ~]# cd mysql-5.6.44
[root@db03 ~/mysql-5.6.44]# ll
total 252
drwxr-xr-x  2 7161 31415  4096 mar 15  2019 build
drwxr-xr-x  2 7161 31415  4096 mar 15  2019 client
drwxr-xr-x  4 7161 31415  4096 mar 15  2019 cmake
-rw-r--r--  1 7161 31415 23415 mar 15  2019 cmakelists.txt
drwxr-xr-x  3 7161 31415    21 mar 15  2019 cmd-line-utils
-rw-r--r--  1 7161 31415 19838 mar 15  2019 config.h.cmake
-rw-r--r--  1 7161 31415 40929 mar 15  2019 configure.cmake
-rw-r--r--  1 7161 31415 17987 mar 15  2019 copying
drwxr-xr-x  2 7161 31415   312 mar 15  2019 dbug
drwxr-xr-x  2 7161 31415    80 mar 15  2019 docs
-rw-r--r--  1 7161 31415 65958 mar 15  2019 doxyfile-perfschema
drwxr-xr-x  4 7161 31415   229 mar 15  2019 extra
drwxr-xr-x  4 7161 31415  4096 mar 15  2019 include
-rw-r--r--  1 7161 31415   333 mar 15  2019 install
drwxr-xr-x  3 7161 31415   224 mar 15  2019 libmysql
drwxr-xr-x  3 7161 31415   204 mar 15  2019 libmysqld
drwxr-xr-x  2 7161 31415   221 mar 15  2019 libservices
drwxr-xr-x  2 7161 31415  4096 mar 15  2019 man
drwxr-xr-x 10 7161 31415   305 mar 15  2019 mysql-test
drwxr-xr-x  2 7161 31415  4096 mar 15  2019 mysys
drwxr-xr-x  2 7161 31415   300 mar 15  2019 mysys_ssl
drwxr-xr-x  9 7161 31415   113 mar 15  2019 packaging
drwxr-xr-x 11 7161 31415   187 mar 15  2019 plugin
-rw-r--r--  1 7161 31415  2496 mar 15  2019 readme
drwxr-xr-x  2 7161 31415  4096 mar 15  2019 regex
drwxr-xr-x  2 7161 31415  4096 mar 15  2019 scripts
drwxr-xr-x  2 7161 31415     6 mar 15  2019 source_downloads
drwxr-xr-x  4 7161 31415 12288 mar 15  2019 sql
drwxr-xr-x  5 7161 31415  4096 mar 15  2019 sql-bench
drwxr-xr-x  2 7161 31415   155 mar 15  2019 sql-common
drwxr-xr-x 13 7161 31415   169 mar 15  2019 storage
drwxr-xr-x  2 7161 31415  4096 mar 15  2019 strings
drwxr-xr-x  5 7161 31415  4096 mar 15  2019 support-files
drwxr-xr-x  2 7161 31415  4096 mar 15  2019 tests
drwxr-xr-x  5 7161 31415    70 mar 15  2019 unittest
-rw-r--r--  1 7161 31415    88 mar 15  2019 version
drwxr-xr-x  3 7161 31415   298 mar 15  2019 vio
drwxr-xr-x  2 7161 31415    32 mar 15  2019 win
drwxr-xr-x 11 7161 31415  4096 mar 15  2019 zlib

确定安装路径存在不存在,不存在则创建 /opt/mysql-5.6.44:

[root@db03 ~/mysql-5.6.44]# ll /opt/ -d
drwxr-xr-x. 2 root root 6 apr 11  2018 /opt/

生成:

[root@db03 ~/mysql-5.6.44]# “注意必须在此目录里面进行生成”
cmake . -dcmake_install_prefix=/opt/mysql-5.6.44 \
-dmysql_datadir=/opt/mysql-5.6.44/data \
-dmysql_unix_addr=/opt/mysql-5.6.44/tmp/mysql.sock \
-ddefault_charset=utf8 \
-ddefault_collation=utf8_general_ci \
-dwith_extra_charsets=all \
-dwith_innobase_storage_engine=1 \
-dwith_federated_storage_engine=1 \
-dwith_blackhole_storage_engine=1 \
-dwithout_example_storage_engine=1 \
-dwith_zlib=bundled \
-dwith_ssl=bundled \
-denabled_local_infile=1 \
-dwith_embedded_server=1 \
-denable_downloads=1 \
-dwith_debug=0


#生成完成后检查
[root@db03 ~/mysql-5.6.44]# echo $?  
等于 0 则没有问题

编译:

[root@db03 ~/mysql-5.6.44]# make

安装:

[root@db03 ~/mysql-5.6.44]# make install

#检查
[root@db03 ~/mysql-5.6.44]# ll /opt/mysql-5.6.44/
total 44
drwxr-xr-x  2 root root  4096 oct 31 03:53 bin
-rw-r--r--  1 root root 17987 mar 15  2019 copying
drwxr-xr-x  3 root root    18 oct 31 03:53 data
drwxr-xr-x  2 root root    55 oct 31 03:53 docs
drwxr-xr-x  3 root root  4096 oct 31 03:53 include
drwxr-xr-x  3 root root   291 oct 31 03:53 lib
drwxr-xr-x  4 root root    30 oct 31 03:53 man
drwxr-xr-x 10 root root  4096 oct 31 03:53 mysql-test
-rw-r--r--  1 root root  2496 mar 15  2019 readme
drwxr-xr-x  2 root root    30 oct 31 03:53 scripts
drwxr-xr-x 28 root root  4096 oct 31 03:53 share
drwxr-xr-x  4 root root  4096 oct 31 03:53 sql-bench
drwxr-xr-x  2 root root   136 oct 31 03:53 support-files

创建用户

[root@db03 ~/mysql-5.6.44]# useradd mysql -s /sbin/nologin -m
[root@db03 ~/mysql-5.6.44]# id mysql
uid=1000(mysql) gid=1000(mysql) groups=1000(mysql)

拷贝启动脚本

[root@db03 ~/mysql-5.6.44]# cd /opt/mysql-5.6.44/support-files/
[root@db03 /opt/mysql-5.6.44/support-files]# cp mysql.server /etc/init.d/mysqld
[root@db03 /opt/mysql-5.6.44/support-files]# ll /etc/init.d/mysqld
-rwxr-xr-x 1 root root 10571 oct 31 03:57 /etc/init.d/mysqld

拷贝配置文件( 存在就覆盖,不存在则创建 )

[root@db03 /opt/mysql-5.6.44/support-files]# cp my-default.cnf /etc/my.cnf
cp: overwrite ‘/etc/my.cnf’? y

创建socket文件存放目录

[root@db03 /opt/mysql-5.6.44/support-files]# mkdir /opt/mysql-5.6.44/tmp
[root@db03 /opt/mysql-5.6.44/support-files]# ll /opt/mysql-5.6.44/tmp -d
drwxr-xr-x 2 root root 6 oct 31 03:59 /opt/mysql-5.6.44/tmp

制作软连接

[root@db03 /opt/mysql-5.6.44/support-files]# cd /opt/mysql-5.6.44/scripts/
[root@db03 /opt/mysql-5.6.44/scripts]# ll
total 36
-rwxr-xr-x 1 root root 34558 oct 31 03:31 mysql_install_db
[root@db03 /opt/mysql-5.6.44/scripts]# ln -s /opt/mysql-5.6.44/ /opt/mysql
[root@db03 /opt/mysql-5.6.44/scripts]# ll /opt/mysql
lrwxrwxrwx 1 root root 18 oct 31 04:01 /opt/mysql -> /opt/mysql-5.6.44/

授权

[root@db03 /opt/mysql-5.6.44/scripts]# chown -r mysql.mysql /opt/*

初始化数据库

[root@db03 /opt/mysql-5.6.44/scripts]# ./mysql_install_db --user=mysql --basedir=/opt/mysql --datadir=/opt/mysql/data

启动mysql服务

[root@db03 /opt/mysql-5.6.44/scripts]# /etc/init.d/mysqld start
starting mysql. success!

添加环境变量

[root@db03 /opt/mysql-5.6.44/scripts]# vim /etc/profile.d/mysql.sh
export path="/opt/mysql/bin:$path"

[root@db03 /opt/mysql-5.6.44/scripts]# source /etc/profile.d/mysql.sh

端口检查

[root@db03 /opt/mysql-5.6.44/scripts]# netstat -lntup |grep 3306
tcp6       0      0 :::3306                 :::*                   listen      25084/mysqld

启动数据库

[root@db03 /opt/mysql-5.6.44/scripts]# mysql
welcome to the mysql monitor. commands end with ; or \g.
your mysql connection id is 2
server version: 5.6.44 source distribution

copyright (c) 2000, 2019, 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>

更改mysql启动的权限并加入systemd管理

vim /usr/lib/systemd/system/mysqld.service
[unit]
description=mysql server
documentation=man:mysqld(8)
documentation=https://dev.mysql.com/doc/refman/en/using-systemd.html
after=network.target
after=syslog.target
[install]
wantedby=multi-user.target
[service]
user=mysql
group=mysql
execstart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
limitnofile = 5000

将mysql 加入systemd管理,并加入开机自启

[root@db01 ~]#  vim /usr/lib/systemd/system/mysqld.service
[unit]
description=mysql server
documentation=man:mysqld(8)
documentation=https://dev.mysql.com/doc/refman/en/using-systemd.html
after=network.target
after=syslog.target
[install]
wantedby=multi-user.target
[service]
user=mysql
group=mysql
execstart=/opt/mysql/bin/mysqld --defaults-file=/etc/my.cnf  ---------------注意安装路径
limitnofile = 5000

[root@db01 ~]# systemctl start mysqld
[root@db01 ~]# systemctl stop mysqld
[root@db01 ~]# systemctl enable mysqld

 


二进制安装 mysql


下载或上传软件包

wget https://downloads.mysql.com/archives/get/file/mysql-5.6.44-linux-glibc2.12-x86_64.tar.gz

解压

[root@db04 ~]# tar xf mysql-5.6.44-linux-glibc2.12-x86_64.tar.gz 
[root@db04 ~]# ll
total 321404
drwxr-xr-x  13 root root       191 oct 31 04:31 mysql-5.6.44-linux-glibc2.12-x86_64
-rw-r--r--   1 root root 329105487 oct 30 10:23 mysql-5.6.44-linux-glibc2.12-x86_64.tar.gz

安装依赖软件包

[root@db04 ~]# yum install -y autoconf libaio*

创建 mysql 用户

[root@db04 ~]# useradd mysql -s /sbin/nologin -m
[root@db04 ~]# id mysql
uid=1000(mysql) gid=1000(mysql) groups=1000(mysql)

将解压后的软件包目录移动到 /opt 目录下面并更改文件名

[root@db04 ~]# mv mysql-5.6.44-linux-glibc2.12-x86_64 /opt/mysql-5.6.44
[root@db04 ~]# cd /opt/mysql-5.6.44/
[root@db04 /opt/mysql-5.6.44]# ll
total 40
drwxr-xr-x  2 root root   4096 oct 31 04:31 bin
-rw-r--r--  1 7161 31415 17987 mar 15  2019 copying
drwxr-xr-x  3 root root     18 oct 31 04:30 data
drwxr-xr-x  2 root root     55 oct 31 04:30 docs
drwxr-xr-x  3 root root   4096 oct 31 04:30 include
drwxr-xr-x  3 root root    316 oct 31 04:31 lib
drwxr-xr-x  4 root root     30 oct 31 04:30 man
drwxr-xr-x 10 root root    291 oct 31 04:30 mysql-test
-rw-r--r--  1 7161 31415  2496 mar 15  2019 readme
drwxr-xr-x  2 root root     30 oct 31 04:30 scripts
drwxr-xr-x 28 root root   4096 oct 31 04:31 share
drwxr-xr-x  4 root root   4096 oct 31 04:31 sql-bench
drwxr-xr-x  2 root root    136 oct 31 04:30 support-files

制作软连接

[root@db04 ~]# ln -s /opt/mysql-5.6.44/ /opt/mysql
[root@db04 ~]# ll /opt/mysql
lrwxrwxrwx 1 root root 18 oct 31 04:37 /opt/mysql -> /opt/mysql-5.6.44/

拷贝启动脚本

[root@db04 /opt/mysql-5.6.44]# cd /opt/mysql-5.6.44/support-files/
[root@db04 /opt/mysql-5.6.44/support-files]# cp mysql.server /etc/init.d/mysqld
[root@db04 /opt/mysql-5.6.44/support-files]# ll /etc/init.d/mysqld
-rwxr-xr-x 1 root root 10565 oct 31 04:40 /etc/init.d/mysqld

拷贝配置文件

[root@db04 /opt/mysql-5.6.44/support-files]# cp my-default.cnf /etc/my.cnf
cp: overwrite ‘/etc/my.cnf’? y
[root@db04 /opt/mysql-5.6.44/support-files]# ll /etc/my.cnf
-rw-r--r--. 1 root root 1126 oct 31 04:41 /etc/my.cnf

初始化数据库

[root@db04 /opt/mysql-5.6.44/support-files]# cd ../scripts/
[root@db04 /opt/mysql-5.6.44/scripts]# ll
total 36
-rwxr-xr-x 1 7161 31415 34558 mar 15  2019 mysql_install_db
[root@db04 /opt/mysql-5.6.44/scripts]# ./mysql_install_db --basedir=/opt/mysql --datadir=/opt/mysql/data --user=mysql

授权 mysql 目录

[root@db04 /opt/mysql-5.6.44/scripts]# chown -r mysql.mysql /opt/*
[root@db04 /opt/mysql-5.6.44/scripts]# ll /opt/
total 0
lrwxrwxrwx  1 mysql mysql  18 oct 31 04:37 mysql -> /opt/mysql-5.6.44/
drwxr-xr-x 13 mysql mysql 223 oct 31 04:43 mysql-5.6.44

修改 mysql 启动脚本和程序

[root@db04 /opt/mysql-5.6.44/scripts]# sed -i 's#/usr/local#/opt#g' /etc/init.d/mysqld /opt/mysql/bin/mysqld_safe

启动 mysqkl

[root@db04 /opt/mysql-5.6.44/scripts]# /etc/init.d/mysqld start
starting mysql.logging to '/opt/mysql/data/db04.err'.
 success!

添加环境变量

[root@db04 /opt/mysql-5.6.44/scripts]# vim /etc/profile.d/mysql.sh
export path="/opt/mysql/bin:$path"
[root@db04 /opt/mysql-5.6.44/scripts]# source /etc/profile.d/mysql.sh

登录mysql数据库

[root@db04 /opt/mysql-5.6.44/scripts]# mysql
welcome to the mysql monitor.  commands end with ; or \g.
your mysql connection id is 1
server version: 5.6.44 mysql community server (gpl)

copyright (c) 2000, 2019, 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> 

将mysql 加入systemd管理,并加入开机自启

[root@db01 ~]#  vim /usr/lib/systemd/system/mysqld.service
[unit]
description=mysql server
documentation=man:mysqld(8)
documentation=https://dev.mysql.com/doc/refman/en/using-systemd.html
after=network.target
after=syslog.target
[install]
wantedby=multi-user.target
[service]
user=mysql
group=mysql
execstart=/opt/mysql/bin/mysqld --defaults-file=/etc/my.cnf  ---------------注意安装路径
limitnofile = 5000

------------------------
[root@db04 ~]# vim /etc/my.cnf

basedir = /opt/mysql        ----------------------更改此处
datadir = /opt/mysql/data   ----------------------更改此处

----------------------------

[root@db01 ~]# systemctl start mysqld
[root@db01 ~]# systemctl stop mysqld
[root@db01 ~]# systemctl enable mysqld

 

 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网