CentOS7上安装MySQL总结

一、MySQL数据库介绍

1、数据库基础知识

  • MySQL是一种开放源代码的关系型数据库管理系统(RDBMS),MySQL数据库系统使用最常用的数据库管理语言–结构化查询语言(SQL)进行数据库管理。

  • MySQL在2008年被SUN公司收购,2009年SUN公司被Oracle公司收购。
  • MySQL5.6功能变化较大,MySQL5.7性能上有很大提升
  • Mariadb为MySQL的一个分支,官方网站:https://mariadb.com, MariaDB主要由SkySQL公司维护,而SkySQL公司团队是由MySQL原作者等大部分原班人马组成的。
  • MySQL版本分为Community社区版、Enterprise企业版、GA(Generally Available)通过版本(通常用于生产环境)、DMR(Development Milestone Release)开发里程碑发布版、RC(Release Candidate)发行候选版本、Beta开放测试版本、Alpha内部测试版本。

数据库(Database)是按照数据结构来组织、存储和管理数据的仓库,它产生于距今六十多年前,随着信息技术和市场的发展,特别是二十世纪九十年代以后,数据管理不再仅仅是存储和管理数据,而转变成用户所需要的各种数据管理的方式。数据库有很多种类型,从最简单的存储有各种数据的表格到能够进行海量数据存储的大型数据库系统都在各个方面得到了广泛的应用。

主流的数据库有:sqlserver,mysql,Oracle、SQLite、Access、MS SQL Server等,本文主要讲述的是mysql

2、数据库管理的功能

a. 将数据保存到文件或内存

b. 接收特定的命令,然后对文件进行相应的操作

说明:对于数据库管理系统,无须自己再去创建文件和文件夹,而是直接传递 命令给相应软件,让其来进行文件操作,他们统称为数据库管理系统(DBMS,Database Management System)

二、MySQL安装配置

1. MySQL的几个常用安装包方法

a.rpm安装 ##不能定义安装路径,默认就是安装/usr/目录下面
b.源码安装
c.二进制免编译安装 ####不用编译,可以指定安装目录

说明:一般在工作中推荐使用二进制免编译安装

2.安装操作步骤

cd /usr/local/src/   ####指定mysql的安装目录,其他目录也行
wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz

解压安装包

tar zxvf mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz

移动重命名

mv mysql-5.6.36-linux-glibc2.5-x86_64 /usr/local/mysql
cd /usr/local/mysql/
ls
bin  COPYING  data  docs  include  lib  man  mysql-test  README  scripts  share  sql-bench  support-files

创建mysql用户

useradd mysql

创建存放mysql数据的目录

[[email protected] mysql]# mkdir /data
[[email protected] mysql]# ls /data/
[[email protected] mysql]#
[[email protected] mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql

说明:在执行这条命令后,怎么验证这条初始化命令是否成功,可以从两点来确认

1)执行命令后,最后会出现两个OK

[[email protected] mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
Installing MySQL system tables...2017-11-29 06:16:59 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-11-29 06:16:59 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2017-11-29 06:16:59 0 [Note] ./bin/mysqld (mysqld 5.6.36) starting as process 6626 ...
2017-11-29 06:16:59 6626 [Note] InnoDB: Using atomics to ref count buffer pool pages
2017-11-29 06:16:59 6626 [Note] InnoDB: The InnoDB memory heap is disabled
2017-11-29 06:16:59 6626 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2017-11-29 06:16:59 6626 [Note] InnoDB: Memory barrier is not used
2017-11-29 06:16:59 6626 [Note] InnoDB: Compressed tables use zlib 1.2.3
2017-11-29 06:16:59 6626 [Note] InnoDB: Using Linux native AIO
2017-11-29 06:16:59 6626 [Note] InnoDB: Using CPU crc32 instructions
2017-11-29 06:16:59 6626 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2017-11-29 06:16:59 6626 [Note] InnoDB: Completed initialization of buffer pool
2017-11-29 06:16:59 6626 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2017-11-29 06:16:59 6626 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2017-11-29 06:16:59 6626 [Note] InnoDB: Database physically writes the file full: wait...
2017-11-29 06:16:59 6626 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2017-11-29 06:17:00 6626 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2017-11-29 06:17:00 6626 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2017-11-29 06:17:00 6626 [Warning] InnoDB: New log files created, LSN=45781
2017-11-29 06:17:00 6626 [Note] InnoDB: Doublewrite buffer not found: creating new
2017-11-29 06:17:00 6626 [Note] InnoDB: Doublewrite buffer created
2017-11-29 06:17:00 6626 [Note] InnoDB: 128 rollback segment(s) are active.
2017-11-29 06:17:00 6626 [Warning] InnoDB: Creating foreign key constraint system tables.
2017-11-29 06:17:00 6626 [Note] InnoDB: Foreign key constraint system tables created
2017-11-29 06:17:00 6626 [Note] InnoDB: Creating tablespace and datafile system tables.
2017-11-29 06:17:00 6626 [Note] InnoDB: Tablespace and datafile system tables created.
2017-11-29 06:17:00 6626 [Note] InnoDB: Waiting for purge to start
2017-11-29 06:17:00 6626 [Note] InnoDB: 5.6.36 started; log sequence number 0
2017-11-29 06:17:00 6626 [Note] Binlog end
2017-11-29 06:17:00 6626 [Note] InnoDB: FTS optimize thread exiting.
2017-11-29 06:17:00 6626 [Note] InnoDB: Starting shutdown...
2017-11-29 06:17:02 6626 [Note] InnoDB: Shutdown completed; log sequence number 1625977
OK
Filling help tables...2017-11-29 06:17:02 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-11-29 06:17:02 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2017-11-29 06:17:02 0 [Note] ./bin/mysqld (mysqld 5.6.36) starting as process 6652 ...
2017-11-29 06:17:02 6652 [Note] InnoDB: Using atomics to ref count buffer pool pages
2017-11-29 06:17:02 6652 [Note] InnoDB: The InnoDB memory heap is disabled
2017-11-29 06:17:02 6652 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2017-11-29 06:17:02 6652 [Note] InnoDB: Memory barrier is not used
2017-11-29 06:17:02 6652 [Note] InnoDB: Compressed tables use zlib 1.2.3
2017-11-29 06:17:02 6652 [Note] InnoDB: Using Linux native AIO
2017-11-29 06:17:02 6652 [Note] InnoDB: Using CPU crc32 instructions
2017-11-29 06:17:02 6652 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2017-11-29 06:17:02 6652 [Note] InnoDB: Completed initialization of buffer pool
2017-11-29 06:17:02 6652 [Note] InnoDB: Highest supported file format is Barracuda.
2017-11-29 06:17:02 6652 [Note] InnoDB: 128 rollback segment(s) are active.
2017-11-29 06:17:02 6652 [Note] InnoDB: Waiting for purge to start
2017-11-29 06:17:02 6652 [Note] InnoDB: 5.6.36 started; log sequence number 1625977
2017-11-29 06:17:02 6652 [Note] Binlog end
2017-11-29 06:17:02 6652 [Note] InnoDB: FTS optimize thread exiting.
2017-11-29 06:17:02 6652 [Note] InnoDB: Starting shutdown...
2017-11-29 06:17:04 6652 [Note] InnoDB: Shutdown completed; log sequence number 1625987
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:
  ./bin/mysqladmin -u root password ‘new-password‘
  ./bin/mysqladmin -u root -h localhost.localdomain password ‘new-password‘
Alternatively you can run:
  ./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 . ; ./bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
  cd mysql-test ; perl mysql-test-run.pl
Please report any problems at http://bugs.mysql.com/
The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
New default config file was created as ./my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings
WARNING: Default config file /etc/my.cnf exists on the system
This file will be read by default by the MySQL server
If you do not want to use this, either remove it, or use the
--defaults-file argument to mysqld_safe when starting the server

2) 确认命令是否执行成功的方法

[[email protected] mysql]#  echo $?
0
说明命令初始化成功

3.拷贝mysql配置文件和启动脚本

[[email protected] mysql]# ls
bin      data  include  man     mysql-test  scripts  sql-bench COPYING  docs  lib      my.cnf  README      share support-files
[[email protected] mysql]# ls support-files/my-default.cnf    ####mysql的启动模板配置文件
support-files/my-default.cnf
[[email protected] mysql]# cat !$
cat support-files/my-default.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It‘s a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....
# socket = .....
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

拷贝mysql启动配置文件

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

查看/etc/my.cnf 是由哪个rpm安装的

[[email protected] mysql-5.6.36-linux-glibc2.5-x86_64]# rpm -qf /etc/my.cnf
mariadb-libs-5.5.52-1.el7.x86_64

编辑/etc/my.cnf配置文件,修改datadir、socket参数为

[mysqld]
datadir=/data/mysql
socket=/tmp/mysql.sock

MySQL数据默认启动脚本为mysql.server

[[email protected] mysql]# ls support-files/
binary-configure  magic  my-default.cnf  mysqld_multi.server  mysql-log-rotate  mysql.server
[[email protected] mysql]# ls support-files/mysql.server
support-files/mysql.server

配置MySQL数据库启动脚本参数,编辑support-files/mysql.server,把basedir、datadir参数修改为

basedir=/usr/local/mysql
datadir=/data/mysql

启动MySQL数据库,并验证进程是否存在

[[email protected] mysql]# systemctl start mysql
[[email protected] mysql]# systemctl status mysql
● mysqld.service - LSB: start and stop MySQL
   Loaded: loaded (/etc/rc.d/init.d/mysqld; bad; vendor preset: disabled)
   Active: active (running) since Mon 2018-03-19 07:25:05 CST; 9s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 20142 ExecStop=/etc/rc.d/init.d/mysqld stop (code=exited, status=0/SUCCESS)
  Process: 21328 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=0/SUCCESS)
   Memory: 436.5M
   CGroup: /system.slice/mysqld.service
           ├─21336 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/centos7.pid
           └─21474 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=...
Mar 19 07:25:03 centos7 systemd[1]: Starting LSB: start and stop MySQL...
Mar 19 07:25:03 centos7 mysqld[21328]: Starting MySQL.Logging to ‘/data/mysql/centos7.err‘.
Mar 19 07:25:05 centos7 mysqld[21328]: . SUCCESS!
Mar 19 07:25:05 centos7 systemd[1]: Started LSB: start and stop MySQL.

查看MySQL进程是否存在

[[email protected] mysql]# ps aux |grep mysql
root     21336  0.0  0.0 115392  1700 ?        S    07:25   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/centos7.pid
mysql    21474  7.5  0.3 1302864 452224 ?      Sl   07:25   0:01 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/centos7.err --pid-file=/data/mysql/centos7.pid --socket=/tmp/mysql.sock
root     21511  0.0  0.0 112664   968 pts/7    S+   07:25   0:00 grep --color=auto mysql

数据库3306端口是否被监听

[[email protected] mysql]# netstat -nlp |grep 3306
tcp6       0      0 :::3306                 :::*                    LISTEN      21474/mysqld
[[email protected] mysql]#

三、技巧经验总结

killall和kill命令在日常运维工作中的使用

killall是杀掉所有正在运行的进程,对于正在向MySQL写数据的时候,如果无法使用kill命令杀掉某个进程,说明此时数据量较大,那么这样的情况下,不能使用kill -9 来杀进程,因为这样会导致正在写入磁盘或者缓存(内存)中的数据没有同步到磁盘,这样可能会丢掉一些数据,这时候只能用killall。

如果无法kill掉某个服务的进程,说明这个服务的数据量的非常大,只有等服务数据同步完才能杀死进程。

原文地址:http://blog.51cto.com/liuleis/2088365

时间: 2025-01-17 20:42:10

CentOS7上安装MySQL总结的相关文章

在CentOS7上安装mysql

安装过程就是几行命令,我们很快就可以安装好.但是对于我这个刚刚开始学习Linux.数据库以及云计算的小白,这几行命令是什么意思呢?我花了点时间去弄懂,然后在这里分享给大家. CentOS 7的yum源中貌似没有正常安装mysql时的mysql-sever文件,需要去官网上下载: 1 三条命令完成安装 # wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm # rpm -ivh mysql-community

在 CentOS7 上安装 MySQL5.7

在 CentOS7 上安装 MySQL5.7 1 通过 SecureCRT 连接到阿里云 CentOS7 服务器: 2 进入到目录 /usr/local/ 中:cd /usr/local/ 3 创建目录 /usr/local/tools,如果有则忽略: mkdir -p tools 4 创建 /usr/local/mysql 目录,如果已存在则忽略:mkdir -p mysql 5 进入到目录 /usr/local/tools 中:cd tools/ 6 查看系统中是否已安装 MySQL 服务:

CentOS7上安装稻壳CMS

CentOS7上安装稻壳CMS 1, 安装用途 为了给某公司建设一个小型网站,租用了一个阿里云ECS服务器,最基础的硬件配置,因此选择了CentOS7操作系统. 稻壳CMS(docCMS)源于深喉咙CMS,使用广泛,配置简单,因此采用其作为建站模板. 2,CentOS7环境安装 阿里云ECS中的CentOS7操作系统属于“裸”操作系统,没有配置基础的Web应用环境.为和稻壳CMS匹配,需安装配置的软件有: ²        Apache服务器Httpd ²        防火墙IPTables

CentOS7上安装POCO

POCO是什么? 看官网说明: Modern, powerful open source C++ class libraries and frameworks for building network- and internet-based applications that run on desktop, server, mobile and embedded systems. 下载地址 强烈建议,唯一下载地址就是官方网站,不要图省事在某些国内站点下载.地址是:(很可惜,这个残疾的网站上发博客

一次在CentOS7上安装部署Zabbix3.0版本及快速进行基本配置的实例

Zabbix3.0的安装.部署.配置,必须基于LAMP环境或是是LNMP环境. 关于LAMP环境的简单快速搭建,见博客:http://afterdawn.blog.51cto.com/7503144/1923139 注意:以下步骤都是在LAMP配置之后进行的. 本文不会再对zabbix-server和zabbix-agent理论知识再进行介绍,建议看完http://afterdawn.blog.51cto.com/7503144/1922502再进行zabbix实战. Zabbix3.0对软硬件

如何在Lunix云服务器上安装Mysql进行远程连接

说说这个服务器上安装mysql真是一个大坑啊 ! 我也不知道自己怎么心血来潮就买一个百度云服务器,然后就想着吧自己做的一些小项目都跑上去.嘿嘿...其实就是想显摆下,写点小应用给不是编程的朋友们使用 ,以满足我自己的小心思,哎呀跑题了,一下没有刹住就给跑偏了,继续说安装的事. 网上百度了许多的教程 ,那叫一个坑啊 !刚开始装JDK 和 Tomcat的时候一切都是顺利.直到开始装Mysql时我不知道是我的服务器不一样还是 我的操作失误!反正就是各种不行 ,那叫一个郁闷.各种方法什么解压tar.gz

在linux(CentOS-6.7_x86_64)上安装mysql成功记录

查看linux服务器的yum源设置: [root@hadoop03 yum.repos.d]# cd /etc/yum.repos.d [[email protected] yum.repos.d]# ll total 4 -rw-r--r--. 1 root root 564 Dec 27 11:27 CentOS-Media.repo [root@hadoop03 yum.repos.d]# vi CentOS-Media.repo # CentOS-Media.repo # # This

Ubuntu上安装MySql过程,以及遇到的一些问题

今天在Ubuntu服务器上安装MySql的时候遇到了一些问题,记录下来,以防以后忘记. 安装环境:Ubuntu14.04 安装命令: //安装Mysal服务端//会提示输入root密码 sudo apt-get install mysql-server //安装Mysql客户端 sudo apt-get install mysql-client sudo apt-get install libmysqlclient-dev 错误一描述: 远程连接MySql的时候出现错误:错误码2203 Can`

在 CentOS7 上安装 zookeeper-3.4.9 服务

在 CentOS7 上安装 zookeeper-3.4.9 服务 1.创建 /usr/local/services/zookeeper 文件夹: mkdir -p /usr/local/services/zookeeper 2.进入到 /usr/local/services/zookeeper 目录中: cd /usr/local/services/zookeeper 3.下载 zookeeper-3.4.9.tar.gz: wget https://mirrors.tuna.tsinghua.