MySQL数据库之CentOS7上安装MySQL总结
小标 2018-09-05 来源 : 阅读 907 评论 0

摘要:本文主要向大家介绍了MySQL数据库之CentOS7上安装MySQL总结 ,通过具体的内容向大家展现,希望对大家学习MySQL数据库有所帮助。

本文主要向大家介绍了MySQL数据库之CentOS7上安装MySQL总结 ,通过具体的内容向大家展现,希望对大家学习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 //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数据的目录

[root@localhost mysql]# mkdir /data 
[root@localhost mysql]# ls /data/
[root@localhost mysql]#
[root@localhost mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
说明:在执行这条命令后,怎么验证这条初始化命令是否成功,可以从两点来确认

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

[root@localhost 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 //bugs.mysql.com/
The latest information about MySQL is available on the web at
//www.mysql.com
Support MySQL by buying support/licenses at //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) 确认命令是否执行成功的方法

[root@localhost mysql]#  echo $?
0
说明命令初始化成功
3.拷贝mysql配置文件和启动脚本

[root@localhost mysql]# ls
bin      data  include  man     mysql-test  scripts  sql-bench COPYING  docs  lib      my.cnf  README      share support-files
[root@localhost mysql]# ls support-files/my-default.cnf    ####mysql的启动模板配置文件
support-files/my-default.cnf
[root@localhost mysql]# cat !$
cat support-files/my-default.cnf
# For advice on how to change settings please see
# //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启动配置文件

[root@localhost mysql]# cp support-files/my-default.cnf /etc/my.cnf 

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

[root@docker 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

[root@localhost mysql]# ls support-files/
binary-configure  magic  my-default.cnf  mysqld_multi.server  mysql-log-rotate  mysql.server
[root@localhost 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数据库,并验证进程是否存在

[root@centos7 mysql]# systemctl start mysql
[root@centos7 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进程是否存在

[root@centos7 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端口是否被监听

[root@centos7 mysql]# netstat -nlp |grep 3306
tcp6       0      0 :::3306                 :::*                    LISTEN      21474/mysqld        
[root@centos7 mysql]#
三、技巧经验总结

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

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

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

以上就介绍了MySQL的相关知识,希望对MySQL有兴趣的朋友有所帮助。了解更多内容,请关注职坐标数据库MySQL频道!

本文由 @小标 发布于职坐标。未经许可,禁止转载。
喜欢 | 0 不喜欢 | 0
看完这篇文章有何感觉?已经有0人表态,0%的人喜欢 快给朋友分享吧~
评论(0)
后参与评论

您输入的评论内容中包含违禁敏感词

我知道了

助您圆梦职场 匹配合适岗位
验证码手机号,获得海同独家IT培训资料
选择就业方向:
人工智能物联网
大数据开发/分析
人工智能Python
Java全栈开发
WEB前端+H5

请输入正确的手机号码

请输入正确的验证码

获取验证码

您今天的短信下发次数太多了,明天再试试吧!

提交

我们会在第一时间安排职业规划师联系您!

您也可以联系我们的职业规划师咨询:

小职老师的微信号:z_zhizuobiao
小职老师的微信号:z_zhizuobiao

版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
 沪公网安备 31011502005948号    

©2015 www.zhizuobiao.com All Rights Reserved

208小时内训课程