mySQL的安装过程

Wesley13
• 阅读 739

安装 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]# lltotal 252drwxr-xr-x  2 7161 31415  4096 Mar 15  2019 BUILDdrwxr-xr-x  2 7161 31415  4096 Mar 15  2019 clientdrwxr-xr-x  4 7161 31415  4096 Mar 15  2019 cmake-rw-r--r--  1 7161 31415 23415 Mar 15  2019 CMakeLists.txtdrwxr-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 COPYINGdrwxr-xr-x  2 7161 31415   312 Mar 15  2019 dbugdrwxr-xr-x  2 7161 31415    80 Mar 15  2019 Docs-rw-r--r--  1 7161 31415 65958 Mar 15  2019 Doxyfile-perfschemadrwxr-xr-x  4 7161 31415   229 Mar 15  2019 extradrwxr-xr-x  4 7161 31415  4096 Mar 15  2019 include-rw-r--r--  1 7161 31415   333 Mar 15  2019 INSTALLdrwxr-xr-x  3 7161 31415   224 Mar 15  2019 libmysqldrwxr-xr-x  3 7161 31415   204 Mar 15  2019 libmysqlddrwxr-xr-x  2 7161 31415   221 Mar 15  2019 libservicesdrwxr-xr-x  2 7161 31415  4096 Mar 15  2019 mandrwxr-xr-x 10 7161 31415   305 Mar 15  2019 mysql-testdrwxr-xr-x  2 7161 31415  4096 Mar 15  2019 mysysdrwxr-xr-x  2 7161 31415   300 Mar 15  2019 mysys_ssldrwxr-xr-x  9 7161 31415   113 Mar 15  2019 packagingdrwxr-xr-x 11 7161 31415   187 Mar 15  2019 plugin-rw-r--r--  1 7161 31415  2496 Mar 15  2019 READMEdrwxr-xr-x  2 7161 31415  4096 Mar 15  2019 regexdrwxr-xr-x  2 7161 31415  4096 Mar 15  2019 scriptsdrwxr-xr-x  2 7161 31415     6 Mar 15  2019 source_downloadsdrwxr-xr-x  4 7161 31415 12288 Mar 15  2019 sqldrwxr-xr-x  5 7161 31415  4096 Mar 15  2019 sql-benchdrwxr-xr-x  2 7161 31415   155 Mar 15  2019 sql-commondrwxr-xr-x 13 7161 31415   169 Mar 15  2019 storagedrwxr-xr-x  2 7161 31415  4096 Mar 15  2019 stringsdrwxr-xr-x  5 7161 31415  4096 Mar 15  2019 support-filesdrwxr-xr-x  2 7161 31415  4096 Mar 15  2019 testsdrwxr-xr-x  5 7161 31415    70 Mar 15  2019 unittest-rw-r--r--  1 7161 31415    88 Mar 15  2019 VERSIONdrwxr-xr-x  3 7161 31415   298 Mar 15  2019 viodrwxr-xr-x  2 7161 31415    32 Mar 15  2019 windrwxr-xr-x 11 7161 31415  4096 Mar 15  2019 zlib

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

[root@db03 ~/mysql-5.6.44]# ll /opt/ -ddrwxr-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 44drwxr-xr-x  2 root root  4096 Oct 31 03:53 bin-rw-r--r--  1 root root 17987 Mar 15  2019 COPYINGdrwxr-xr-x  3 root root    18 Oct 31 03:53 datadrwxr-xr-x  2 root root    55 Oct 31 03:53 docsdrwxr-xr-x  3 root root  4096 Oct 31 03:53 includedrwxr-xr-x  3 root root   291 Oct 31 03:53 libdrwxr-xr-x  4 root root    30 Oct 31 03:53 mandrwxr-xr-x 10 root root  4096 Oct 31 03:53 mysql-test-rw-r--r--  1 root root  2496 Mar 15  2019 READMEdrwxr-xr-x  2 root root    30 Oct 31 03:53 scriptsdrwxr-xr-x 28 root root  4096 Oct 31 03:53 sharedrwxr-xr-x  4 root root  4096 Oct 31 03:53 sql-benchdrwxr-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 mysqluid=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.cnfcp: 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 -ddrwxr-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]# lltotal 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/mysqllrwxrwxrwx 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 startStarting MySQL. SUCCESS! 

添加环境变量

[root@db03 /opt/mysql-5.6.44/scripts]# vim /etc/profile.d/mysql.shexport 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 3306tcp6       0      0 :::3306                 :::*                   LISTEN      25084/mysqld 

启动数据库

[root@db03 /opt/mysql-5.6.44/scripts]# mysqlWelcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 2Server 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 itsaffiliates. Other names may be trademarks of their respectiveowners.​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 ServerDocumentation=man:mysqld(8)Documentation=https://dev.mysql.com/doc/refman/en/using-systemd.htmlAfter=network.targetAfter=syslog.target[Install]WantedBy=multi-user.target[Service]User=mysqlGroup=mysqlExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnfLimitNOFILE = 5000

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

[root@db01 ~]#  vim /usr/lib/systemd/system/mysqld.service[Unit]Description=MySQL ServerDocumentation=man:mysqld(8)Documentation=https://dev.mysql.com/doc/refman/en/using-systemd.htmlAfter=network.targetAfter=syslog.target[Install]WantedBy=multi-user.target[Service]User=mysqlGroup=mysqlExecStart=/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 ~]# lltotal 321404drwxr-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 mysqluid=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
点赞
收藏
评论区
推荐文章
blmius blmius
3年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
皕杰报表之UUID
​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为
待兔 待兔
3个月前
手写Java HashMap源码
HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22
Jacquelyn38 Jacquelyn38
3年前
2020年前端实用代码段,为你的工作保驾护航
有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )
Stella981 Stella981
3年前
Python3:sqlalchemy对mysql数据库操作,非sql语句
Python3:sqlalchemy对mysql数据库操作,非sql语句python3authorlizmdatetime2018020110:00:00coding:utf8'''
Wesley13 Wesley13
3年前
mysql设置时区
mysql设置时区mysql\_query("SETtime\_zone'8:00'")ordie('时区设置失败,请联系管理员!');中国在东8区所以加8方法二:selectcount(user\_id)asdevice,CONVERT\_TZ(FROM\_UNIXTIME(reg\_time),'08:00','0
Stella981 Stella981
3年前
Android蓝牙连接汽车OBD设备
//设备连接public class BluetoothConnect implements Runnable {    private static final UUID CONNECT_UUID  UUID.fromString("0000110100001000800000805F9B34FB");
Wesley13 Wesley13
3年前
MySQL部分从库上面因为大量的临时表tmp_table造成慢查询
背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_
为什么mysql不推荐使用雪花ID作为主键
作者:毛辰飞背景在mysql中设计表的时候,mysql官方推荐不要使用uuid或者不连续不重复的雪花id(long形且唯一),而是推荐连续自增的主键id,官方的推荐是auto_increment,那么为什么不建议采用uuid,使用uuid究
Python进阶者 Python进阶者
9个月前
Excel中这日期老是出来00:00:00,怎么用Pandas把这个去除
大家好,我是皮皮。一、前言前几天在Python白银交流群【上海新年人】问了一个Pandas数据筛选的问题。问题如下:这日期老是出来00:00:00,怎么把这个去除。二、实现过程后来【论草莓如何成为冻干莓】给了一个思路和代码如下:pd.toexcel之前把这