mysql数据库安装实战(二进制安装)

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
云数据库 RDS PostgreSQL,集群系列 2核4GB
简介:

1    安装环境准备:

环境:CentOS 6.8 64位

安装二进制分发版 mysql-5.5.49-linux2.6-x86_64.tar.gz

myseql 二进制包下载地址:

https://downloads.mysql.com/archives/community/

http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.49-linux2.6-x86_64.tar.gz

wKiom1mddefw2gTKAAO2cAlZY60319.jpg

wKiom1mddfKCBOiDAAQzHGUTBBY147.jpg

    上传mysql-5.5.49-linux2.6-x86_64.tar.gz 二进制包到/home/oldboy/tools目录下面

1
2
3
4
5
6
7
[root@web01 ~] # cd /home/oldboy/tools
[root@web01 tools] # rz -y       #上传mysql-5.5.49-linux2.6-x86_64.tar.gz到当前目录下
[root@web01 tools] # ls -hil
total 179M
261195 -rw-r--r-- 1 root root 178M Aug 23 19:57 mysql-5.5.49-linux2.6-x86_64. tar .gz
261198 drwxr-xr-x 9 1001 1001 4.0K Aug 19 16:11 nginx-1.6.3
261196 -rw-r--r-- 1 root root 787K Apr  8  2015 nginx-1.6.3. tar .gz

    创建用户:命令useradd mysql -s /sbin/nologin -M和useradd -s /sbin/nologin mysql -M是一样的。

1
2
3
[root@web01 tools] # useradd -s /sbin/nologin mysql -M
[root@web01 tools] # id mysql
uid=504(mysql) gid=504(mysql)  groups =504(mysql)

    解压mysql二进制包:

1
2
3
4
[root@web01 tools] #  tar xf mysql-5.5.49-linux2.6-x86_64.tar.gz
[root@web01 tools] # ls
mysql-5.5.49-linux2.6-x86_64         nginx-1.6.3
mysql-5.5.49-linux2.6-x86_64. tar .gz  nginx-1.6.3. tar .gz

    移动mysql

1
[root@web01 tools] # mv mysql-5.5.49-linux2.6-x86_64 /application/mysql-5.5.49

    创建软链接

1
[root@web01 tools] # ln -s /application/mysql-5.5.49/ /application/mysql

    授权

1
2
3
4
5
[root@web01 tools] # cd /application/mysql
[root@web01 mysql] # chown -R mysql.mysql /application/mysql/
[root@web01 mysql] # ls
COPYING         README  data  include   man          scripts  sql-bench
INSTALL-BINARY  bin     docs  lib      mysql- test   share    support-files

    安装mysql并指定mysql根路径和数据文件路径

1
[root@web01 mysql] # ./scripts/mysql_install_db --basedir=/application/mysql/ --datadir=/application/mysql/data/ --user=mysql

此步骤操作看到如下两个OK就代表安装完成了。

[root@web01 mysql]# ./scripts/mysql_install_db --basedir=/application/mysql/ --datadir=/application/mysql/data/
Installing MySQL system tables...
170823 21:00:53 [Note] /application/mysql//bin/mysqld (mysqld 5.5.49) starting as process 1756 ...
OK
Filling help tables...
170823 21:00:53 [Note] /application/mysql//bin/mysqld (mysqld 5.5.49) starting as process 1763 ...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/application/mysql//bin/mysqladmin -u root password 'new-password'
/application/mysql//bin/mysqladmin -u root -h web01 password 'new-password'

Alternatively you can run:
/application/mysql//bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /application/mysql/ ; /application/mysql//bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd /application/mysql//mysql-test ; perl mysql-test-run.pl

Please report any problems at http://bugs.mysql.com/

    上面的安装就生成内部两个管理库:mysql和performance_schema

1
2
3
4
5
[root@web01 mysql] # ll data/
total 12
drwx------ 2 mysql root  4096 Aug 23 21:00 mysql
drwx------ 2 mysql mysql 4096 Aug 23 21:00 performance_schema
drwxr-xr-x 2 mysql mysql 4096 Aug 23 20:46  test

    做个调整

1
2
[root@web01 mysql] # cd bin/
[root@web01 bin] # less mysqld_safe

    启动文件mysqld_safe默认的路径是/usr/local需要替换成/application/,测试下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
[root@web01 bin] # sed 's#/usr/local/#/application/#g' mysqld_safe |grep application
if  echo  '/application/mysql/share'  grep  '^/application/mysql'  /dev/null
   relpkgdata=` echo  '/application/mysql/share'  sed  -e  's,^/application/mysql,,'  -e  's,^/,,'  -e  's,^,./,' `
   relpkgdata= '/application/mysql/share'
   MY_BASEDIR_VERSION= '/application/mysql'
   ledir= '/application/mysql/bin'
   DATADIR= /application/mysql/data
elif  test  -x  /application/mysql/bin/my_print_defaults
   print_defaults= "/application/mysql/bin/my_print_defaults"
elif  test  -x  /application/mysql/bin/mysql_print_defaults
   print_defaults= "/application/mysql/bin/mysql_print_defaults"
     plugin_dir= '/application/mysql/lib/plugin'
[root@web01 bin] # sed 's#/usr/local/#/application/#g' mysqld_safe |grep application
if  echo  '/application/mysql/share'  grep  '^/application/mysql'  /dev/null
   relpkgdata=` echo  '/application/mysql/share'  sed  -e  's,^/application/mysql,,'  -e  's,^/,,'  -e  's,^,./,' `
   relpkgdata= '/application/mysql/share'
   MY_BASEDIR_VERSION= '/application/mysql'
   ledir= '/application/mysql/bin'
   DATADIR= /application/mysql/data
elif  test  -x  /application/mysql/bin/my_print_defaults
   print_defaults= "/application/mysql/bin/my_print_defaults"
elif  test  -x  /application/mysql/bin/mysql_print_defaults
   print_defaults= "/application/mysql/bin/mysql_print_defaults"
     plugin_dir= '/application/mysql/lib/plugin'

    测试完成后直接替换

1
[root@web01 bin] # sed -i 's#/usr/local/#/application/#g' mysqld_safe

    替换配置文件

1
2
[root@web01 mysql] # cp support-files/my-small.cnf /etc/my.cnf 
cp : overwrite ` /etc/my .cnf'? y

    启动mysql,启动命令为/application/mysql/bin/mysqld_safe --user=mysql &

1
2
3
4
5
[root@web01 mysql] # /application/mysql/bin/mysqld_safe --user=mysql &
[1] 2185
[root@web01 mysql] # 170823 21:37:36 mysqld_safe Logging to '/application/mysql/data/web01.err'.
170823 21:37:36 mysqld_safe Starting mysqld daemon with databases from  /application/mysql/data
^C

    查看进程是否生成

1
2
3
[root@web01 mysql] # lsof -i :3306
COMMAND  PID  USER   FD   TYPE DEVICE SIZE /OFF  NODE NAME
mysqld  2415 mysql   10u  IPv4  20041      0t0  TCP *:mysql (LISTEN)

    优化

1
2
3
[root@web01 mysql] # PATH="/application/mysql/bin:$PATH"
[root@web01 mysql] # which mysql
/application/mysql/bin/mysql

    配置mysql命令的全局使用路径:用vim /etc/profile 把export PATH="/application/mysql/bin:$PATH"追加到/etc/profile最后一行

1
2
[root@web01 mysql] # tail -1 /etc/profile
export  PATH= "/application/mysql/bin:$PATH"

    使配置生效

1
[root@web01 mysql] # . /etc/profile

    已生效

1
2
[root@web01 mysql] # echo $PATH
/application/mysql/bin : /application/mysql/bin : /usr/local/sbin : /usr/local/bin : /sbin : /bin : /usr/sbin : /usr/bin : /root/bin

    此时输入mysql就直接进来了

1
2
3
4
5
6
7
8
9
10
[root@web01 mysql] # mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection  id  is 1
Server version: 5.5.49 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, 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>

    这就表示成功了,quit退出mysql,再做一个调整

1
mysql> quit

    调整如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@web01 mysql] # ll support-files/
total 96
-rwxr-xr-x 1 mysql mysql  1153 Mar  1  2016 binary-configure
-rw-r--r-- 1 mysql mysql  4528 Mar  1  2016 config.huge.ini
-rw-r--r-- 1 mysql mysql  2382 Mar  1  2016 config.medium.ini
-rw-r--r-- 1 mysql mysql  1626 Mar  1  2016 config.small.ini
-rw-r--r-- 1 mysql mysql   773 Mar  1  2016 magic
-rw-r--r-- 1 mysql mysql  4691 Mar  1  2016 my-huge.cnf
-rw-r--r-- 1 mysql mysql 19759 Mar  1  2016 my-innodb-heavy-4G.cnf
-rw-r--r-- 1 mysql mysql  4665 Mar  1  2016 my-large.cnf
-rw-r--r-- 1 mysql mysql  4676 Mar  1  2016 my-medium.cnf
-rw-r--r-- 1 mysql mysql  2840 Mar  1  2016 my-small.cnf
-rwxr-xr-x 1 mysql mysql   839 Mar  1  2016 mysql-log-rotate
-rwxr-xr-x 1 mysql mysql 10880 Mar  1  2016 mysql.server
-rwxr-xr-x 1 mysql mysql  1061 Mar  1  2016 mysqld_multi.server
-rw-r--r-- 1 mysql mysql  1326 Mar  1  2016 ndb-config-2-node.ini
1
2
3
[root@web01 mysql] # sed -i 's#/usr/local/#/application/#g' support-files/mysql.server 
[root@web01 mysql] # cp support-files/mysql.server /etc/init.d/mysqld
[root@web01 mysql] # chmod +x /etc/init.d/mysqld

    stop mysql服务

1
2
3
4
[root@web01 mysql] # /etc/init.d/mysqld stop
Shutting down MySQL.170823 21:57:02 mysqld_safe mysqld from pid  file  /application/mysql/data/web01 .pid ended
  SUCCESS! 
[1]+  Done                     /application/mysql/bin/mysqld_safe  --user=mysql
1
[root@web01 mysql] # lsof -i :3306

    start mysql服务,出来结果

1
2
3
4
5
[root@web01 mysql] # /etc/init.d/mysqld start
Starting MySQL.. SUCCESS! 
[root@web01 mysql] # lsof -i :3306
COMMAND  PID  USER   FD   TYPE DEVICE SIZE /OFF  NODE NAME
mysqld  2742 mysql   10u  IPv4  20558      0t0  TCP *:mysql (LISTEN)

    设置开机自启动

1
2
3
[root@web01 mysql] # chkconfig --add mysqld
[root@web01 mysql] # chkconfig --list mysqld
mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off

    判断mysql是否安装成功,直接输入mysql能进入mysql界面就说明成功了,如下所示成功安装myslq。

1
2
3
4
5
6
7
8
9
10
[root@web01 mysql] # mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection  id  is 1
Server version: 5.5.49 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, 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>


总结:

wKioL1mdnB3QgxUoAAF202jwHQY740.jpg

wKiom1mdnCjjRbEEAAAp4NFdq78751.jpg

本文转自sandshell博客51CTO博客,原文链接http://blog.51cto.com/sandshell/1958781如需转载请自行联系原作者

sandshell
相关实践学习
如何快速连接云数据库RDS MySQL
本场景介绍如何通过阿里云数据管理服务DMS快速连接云数据库RDS MySQL,然后进行数据表的CRUD操作。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
21天前
|
存储 SQL 关系型数据库
MySQL日志详解——日志分类、二进制日志bin log、回滚日志undo log、重做日志redo log
MySQL日志详解——日志分类、二进制日志bin log、回滚日志undo log、重做日志redo log、原理、写入过程;binlog与redolog区别、update语句的执行流程、两阶段提交、主从复制、三种日志的使用场景;查询日志、慢查询日志、错误日志等其他几类日志
MySQL日志详解——日志分类、二进制日志bin log、回滚日志undo log、重做日志redo log
|
22天前
|
关系型数据库 MySQL 数据库
Docker Compose V2 安装常用数据库MySQL+Mongo
以上内容涵盖了使用 Docker Compose 安装和管理 MySQL 和 MongoDB 的详细步骤,希望对您有所帮助。
122 42
|
1月前
|
SQL NoSQL 关系型数据库
超强数据库管理软件推荐-没有之一-还在用Navicat管理本地数据库的吗?还在为Navicat寻求绿色版或者购买正版的费用望而却步吗?DBeaver让你解决所有数据库本地编写问题-优雅草央千澈-DBeaver下载和安装
超强数据库管理软件推荐-没有之一-还在用Navicat管理本地数据库的吗?还在为Navicat寻求绿色版或者购买正版的费用望而却步吗?DBeaver让你解决所有数据库本地编写问题-优雅草央千澈-DBeaver下载和安装
134 18
超强数据库管理软件推荐-没有之一-还在用Navicat管理本地数据库的吗?还在为Navicat寻求绿色版或者购买正版的费用望而却步吗?DBeaver让你解决所有数据库本地编写问题-优雅草央千澈-DBeaver下载和安装
|
1月前
|
存储 缓存 监控
71.7万/秒到1.4万/秒!数据库查询优化实战
在现代计算机系统中,程序的局部性原理是优化性能的关键。通过利用时间局部性和空间局部性,可以显著提升数据访问效率,减少高开销的操作如内存访问和网络 I/O。本文将探讨如何利用空间局部性原理,在实际案例中减少数据库查询量,并通过详细的监控和优化措施确保系统的稳定性和高效性。
71.7万/秒到1.4万/秒!数据库查询优化实战
|
1月前
|
安全 关系型数据库 MySQL
CentOS7仅安装部署MySQL80客户端
通过上述步骤,你可以在CentOS 7上成功安装并配置MySQL 8.0客户端。这个过程确保你能够使用MySQL客户端工具连接和管理远程的MySQL数据库,而不需要在本地安装MySQL服务器。定期更新MySQL客户端可以确保你使用的是最新的功能和安全修复。
206 16
|
2月前
|
关系型数据库 MySQL 数据库
【MySQL基础篇】MySQL概述、Windows下载MySQL8.0超详细图文安装教程
在这一章节,主要介绍两个部分,数据库相关概念及MySQL数据库的介绍、下载、安装、启动及连接。接着,详细描述了MySQL 8.0的版本选择与下载,推荐使用社区版(免费)。安装过程包括自定义安装路径、配置环境变量、启动和停止服务、以及客户端连接测试。此外,还提供了在同一台电脑上安装多个MySQL版本的方法及卸载步骤。最后,解释了关系型数据库(RDBMS)的特点,即基于二维表存储数据,使用SQL语言进行操作,格式统一且便于维护。通过具体的结构图展示了MySQL的数据模型,说明了数据库服务器、数据库、表和记录之间的层次关系。
【MySQL基础篇】MySQL概述、Windows下载MySQL8.0超详细图文安装教程
|
2月前
|
NoSQL 关系型数据库 Redis
《docker高级篇(大厂进阶):1.Docker复杂安装详说》包括:安装mysql主从复制、安装redis集群
《docker高级篇(大厂进阶):1.Docker复杂安装详说》包括:安装mysql主从复制、安装redis集群
137 14
|
1月前
|
关系型数据库 MySQL 应用服务中间件
《docker基础篇:8.Docker常规安装简介》包括:docker常规安装总体步骤、安装tomcat、安装mysql、安装redis
《docker基础篇:8.Docker常规安装简介》包括:docker常规安装总体步骤、安装tomcat、安装mysql、安装redis
135 7
|
2月前
|
安全 关系型数据库 MySQL
Windows Server 安装 MySQL 8.0 详细指南
安装 MySQL 需要谨慎,特别注意安全配置和权限管理。根据实际业务需求调整配置,确保数据库的性能和安全。
302 9
|
2月前
|
SQL Java 数据库连接
JDBC编程安装———通过代码操控数据库
本文,教你从0开始学习JBCD,包括驱动包的下载安装调试设置,以及java是如何通过JBDC实现对数据库的操作,以及代码的分析,超级详细

热门文章

最新文章