MySQL学习系列(1) -- MySQL数据库的介绍和快速安装

来源:互联网 发布:数据库开发与管理 编辑:程序博客网 时间:2024/05/20 07:19

===================================================================================================

0. summary

 

    1. MySQL官方网站介绍

    .  1.1 Developer Zone - MySQL工程师版块

    .  1.2 Downloads - MySQL下载

    .  1.3 Documentation - MySQL文档

    2. MySQL下载

    3. MySQL安装

    .  3.1 快速安装5.6.31

    .  3.2 mysqld_safe

    .  3.3 mysqld

    .  3.4 mysql.server

        .  3.4.1 mysql.server stop的实质

 

===================================================================================================

1. MySQL官方网站介绍

 

http://www.mysql.com/

 

*************************************************

1.1 Developer Zone - MySQL工程师版块

 

http://dev.mysql.com/

 

Articles     - Oracle MySQL工程师博客

Forums       - 论坛

Planet MySQL - 和MySQL相关从业人员的博客

Bugs         - MySQL BugList

Worklog      - 开发记录

Labs         - MySQL实验特性,还没有稳定版本,会慢慢上线

 

*************************************************

1.2 Downloads - MySQL下载

 

http://www.mysql.com/downloads/

 

MySQL Enterprise Edition -MySQL企业版本

MySQL Cluster CGE        - 独立的一套产品,使用的是NDB Cluster存储引擎,与其他两个产品没有关系。

MySQL CommunityEdition  - 社区版

.   MySQL Community Server   - MySQL Server

.   MySQL Cluster            - MySQL Cluster社区版本

.   MySQL Fabric             - Mysql中间件

.   MySQL Router             - 路由,可以结合Fabric一起使用

.   MySQL Utilities          - MySQL应用程序包

.   MySQL Workbench          - 图型化客户端,跨平台。可以绑定MySQL Utilities

.   MySQL Connectors         - 驱动

 

*************************************************

1.3 Documentation - MySQL文档

 

http://dev.mysql.com/doc/

 

推荐下载epub版本,适合手机、移动设备

 

MySQL-5.7 EPUB版本下载地址:

http://downloads.mysql.com/docs/refman-5.7-en.epub

 

===================================================================================================

2. MySQL下载

 

http://dev.mysql.com/downloads/mysql/

 

Source Code   - 主要作用是为了让开发人员研究源码以及crash时候可以定位到哪个文件的哪一行。自己编译对性能提升不明显。

Linux-Generic - 推荐下载的版本,其他系统版本安装路径都是根据自己发行版本,并且RPM包不容易一台机器安装多个MySQL版本。

 

下载地址:

http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.31-linux-glibc2.5-x86_64.tar.gz

http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.13-linux-glibc2.5-x86_64.tar.gz

 

不推荐使用5.5的版本,bug大多在5.6才修复。

 

===================================================================================================

3. MySQL安装

 

MySQL的安装比较简单,将安装包解压后打开INSTALL_BINARY文件,按照shell>开头的步骤进行操作。

 

*************************************************

3.1 安装5.6.31

 

5.6.31的解压包里没有包含INSTALL_BINARY, 可以拿MySQL-5.6.27为例,如下:

shell> yum searchlibaio  # search for infoshell> yum installlibaio # install libraryshell> groupadd mysqlshell> useradd -r -gmysql mysqlshell> cd /usr/localshell> tar zxvf/path/to/mysql-VERSION-OS.tar.gzshell> ln -sfull-path-to-mysql-VERSION-OS mysqlshell> cd mysqlshell> chown -R mysql .shell> chgrp -R mysql .shell>scripts/mysql_install_db --user=mysqlshell> chown -R root .shell> chown -R mysqldatashell> bin/mysqld_safe--user=mysql &# Next command is optionalshell> cpsupport-files/mysql.server /etc/init.d/mysql.server

安装过程如下: 

[root@lab11g ~]# rpm -qa |grep libaio        ---- 异步IO的包libaio-0.3.106-5libaio-0.3.106-5libaio-devel-0.3.106-5libaio-devel-0.3.106-5[root@lab11g ~]# groupaddmysql[root@lab11g ~]# useradd -r-g mysql mysql[root@lab11g ~]# cd/usr/local[root@lab11g local]# tarzxf /install/mysql-5.6.31-linux-glibc2.5-x86_64.tar.gz[root@lab11g local]# ln -s/usr/local/mysql-5.6.31-linux-glibc2.5-x86_64 mysql      ---- 创建mysql的快捷链接,取消是unlink[root@lab11g local]# cdmysql[root@lab11g mysql]# chown-R mysql .[root@lab11g mysql]# chgrp-R mysql .[root@lab11g mysql]#scripts/mysql_install_db --user=mysql                       ---- 初始化mysql数据库Installing MySQL systemtables...2016-06-25 15:49:58 0 [Warning] TIMESTAMP with implicit DEFAULT valueis deprecated. Please use --explicit_defaults_for_timestamp server option (seedocumentation for more details).2016-06-25 15:49:58 0[Note] ./bin/mysqld (mysqld 5.6.31) starting as process 7247 ...2016-06-25 15:49:58 7247[Note] InnoDB: Using atomics to ref count buffer pool pages2016-06-25 15:49:58 7247[Note] InnoDB: The InnoDB memory heap is disabled2016-06-25 15:49:58 7247[Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins2016-06-25 15:49:58 7247[Note] InnoDB: Memory barrier is not used2016-06-25 15:49:58 7247[Note] InnoDB: Compressed tables use zlib 1.2.32016-06-25 15:49:58 7247[Note] InnoDB: Using Linux native AIO2016-06-25 15:49:58 7247[Note] InnoDB: Using CPU crc32 instructions2016-06-25 15:49:58 7247[Note] InnoDB: Initializing buffer pool, size = 128.0M2016-06-25 15:49:58 7247[Note] InnoDB: Completed initialization of buffer pool2016-06-25 15:49:58 7247[Note] InnoDB: The first specified data file ./ibdata1 did not exist: a newdatabase to be created!2016-06-25 15:49:58 7247[Note] InnoDB: Setting file ./ibdata1 size to 12 MB2016-06-25 15:49:58 7247[Note] InnoDB: Database physically writes the file full: wait...2016-06-25 15:49:58 7247[Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB2016-06-25 15:49:58 7247[Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB2016-06-25 15:49:59 7247[Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile02016-06-25 15:49:59 7247[Warning] InnoDB: New log files created, LSN=457812016-06-25 15:49:59 7247[Note] InnoDB: Doublewrite buffer not found: creating new2016-06-25 15:49:59 7247[Note] InnoDB: Doublewrite buffer created2016-06-25 15:49:59 7247[Note] InnoDB: 128 rollback segment(s) are active.2016-06-25 15:49:59 7247[Warning] InnoDB: Creating foreign key constraint system tables.2016-06-25 15:49:59 7247[Note] InnoDB: Foreign key constraint system tables created2016-06-25 15:49:59 7247[Note] InnoDB: Creating tablespace and datafile system tables.2016-06-25 15:49:59 7247[Note] InnoDB: Tablespace and datafile system tables created.2016-06-25 15:49:59 7247[Note] InnoDB: 5.6.31 started; log sequence number 02016-06-25 15:49:59 7247[Note] Binlog end2016-06-25 15:49:59 7247[Note] InnoDB: FTS optimize thread exiting.2016-06-25 15:49:59 7247[Note] InnoDB: Starting shutdown...2016-06-25 15:50:01 7247[Note] InnoDB: Shutdown completed; log sequence number 1625977OK Filling helptables...2016-06-25 15:50:01 0 [Warning] TIMESTAMP with implicit DEFAULT valueis deprecated. Please use --explicit_defaults_for_timestamp server option (seedocumentation for more details).2016-06-25 15:50:01 0[Note] ./bin/mysqld (mysqld 5.6.31) starting as process 7273 ...2016-06-25 15:50:01 7273[Note] InnoDB: Using atomics to ref count buffer pool pages2016-06-25 15:50:01 7273[Note] InnoDB: The InnoDB memory heap is disabled2016-06-25 15:50:01 7273[Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins2016-06-25 15:50:01 7273[Note] InnoDB: Memory barrier is not used2016-06-25 15:50:01 7273[Note] InnoDB: Compressed tables use zlib 1.2.32016-06-25 15:50:01 7273[Note] InnoDB: Using Linux native AIO2016-06-25 15:50:01 7273[Note] InnoDB: Using CPU crc32 instructions2016-06-25 15:50:01 7273[Note] InnoDB: Initializing buffer pool, size = 128.0M2016-06-25 15:50:01 7273[Note] InnoDB: Completed initialization of buffer pool2016-06-25 15:50:01 7273[Note] InnoDB: Highest supported file format is Barracuda.2016-06-25 15:50:01 7273[Note] InnoDB: 128 rollback segment(s) are active.2016-06-25 15:50:01 7273[Note] InnoDB: Waiting for purge to start2016-06-25 15:50:01 7273[Note] InnoDB: 5.6.31 started; log sequence number 16259772016-06-25 15:50:01 7273[Note] Binlog end2016-06-25 15:50:01 7273[Note] InnoDB: FTS optimize thread exiting.2016-06-25 15:50:01 7273[Note] InnoDB: Starting shutdown...2016-06-25 15:50:02 7273[Note] InnoDB: Shutdown completed; log sequence number 1625987OK To start mysqld at boottime you have to copysupport-files/mysql.serverto the right place for your system PLEASE REMEMBER TO SET APASSWORD 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 lab11g password'new-password' Alternatively you can run:   ./bin/mysql_secure_installation which will also give youthe option of removing the testdatabases and anonymoususer created by default.  This isstrongly recommended forproduction servers. See the manual for moreinstructions. You can start the MySQLdaemon with:   cd . ; ./bin/mysqld_safe & You can test the MySQLdaemon with mysql-test-run.pl   cd mysql-test ; perl mysql-test-run.pl Please report any problemsat http://bugs.mysql.com/ The latest informationabout MySQL is available on the web at   http://www.mysql.com Support MySQL by buyingsupport/licenses at http://shop.mysql.com New default config file wascreated as ./my.cnf andwill be used by default bythe server when you start it.You may edit this file tochange server settings [root@lab11g mysql]# chown-R root .[root@lab11g mysql]# chown-R mysql data[root@lab11g mysql]#bin/mysqld_safe --user=mysql &                   ----通过mysql用户来启动进程到后台[1] 7306[root@lab11g mysql]# 16062515:50:22 mysqld_safe Logging to '/usr/local/mysql/data/lab11g.err'.160625 15:50:22 mysqld_safeStarting mysqld daemon with databases from /usr/local/mysql/data [root@lab11g mysql]# cpsupport-files/mysql.server /etc/init.d/mysql.server ---- 可选步骤

初始化mysql数据库那步骤之后可以发现data下面多了一些文件,原来是空的,如下:

[root@lab11g mysql]# lldata总计 110736-rw-rw---- 1 mysqlmysql       56 06-25 15:50 auto.cnf-rw-rw---- 1 mysql mysql12582912 06-25 15:50 ibdata1-rw-rw---- 1 mysql mysql50331648 06-25 15:50 ib_logfile0-rw-rw---- 1 mysql mysql50331648 06-25 15:49 ib_logfile1-rw-r----- 1 mysqlroot      2146 06-25 15:50 lab11g.err                      ---- 默认是hostname.err-rw-rw---- 1 mysqlmysql        5 06-25 15:50 lab11g.piddrwx------ 2 mysqlmysql     4096 06-25 15:49 mysqldrwx------ 2 mysqlmysql     4096 06-25 15:49performance_schemadrwxr-xr-x 2 mysqlmysql     4096 06-25 15:49 test

#### lab11g.err #### 

160625 15:50:22 mysqld_safeStarting mysqld daemon with databases from /usr/local/mysql/data2016-06-25 15:50:23 0[Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use--explicit_defaults_for_timestamp server option (see documentation for moredetails).2016-06-25 15:50:23 0[Note] /usr/local/mysql/bin/mysqld (mysqld 5.6.31) starting as process 7396 ...2016-06-25 15:50:23 7396[Note] Plugin 'FEDERATED' is disabled.2016-06-25 15:50:23 7396[Note] InnoDB: Using atomics to ref count buffer pool pages2016-06-25 15:50:23 7396[Note] InnoDB: The InnoDB memory heap is disabled2016-06-25 15:50:23 7396[Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins2016-06-25 15:50:23 7396[Note] InnoDB: Memory barrier is not used......

如果有错误的话会有Error的信息。

 

另外还有种可能,操作系统已经安装了部分包,存在my.cnf配置文件,比如:

 

/etc/my.cnf    ---- rhel

/etc/mysql/my.cnf  ---- debain

 

初始化时候会以配置文件里面的信息去启动,比如:

 

datadir = /data/mysql_data

 

如果没有权限,初始化就会失败。该目录权限应该是mysql:mysql.

 

*************************************************

3.2 mysqld_safe

 

mysqld_safe是mysqld的守护进程,只要mysqld_safe存在,mysqld终止后会自动去重启。如下: 

[root@lab11g mysql]# ps -ef| grep mysqldroot      7306 5918  0 15:50 pts/2    00:00:00 /bin/sh bin/mysqld_safe--user=mysqlmysql     7396  7306  0 15:50 pts/2    00:00:00 /usr/local/mysql/bin/mysqld--basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin--user=mysql --log-error=/usr/local/mysql/data/lab11g.err--pid-file=/usr/local/mysql/data/lab11g.pidroot      7645 5918  0 16:01 pts/2    00:00:00 grep mysqld[root@lab11g mysql]# kill-9 7396[root@lab11g mysql]#bin/mysqld_safe: line 166:  7396 已杀死                  nohup/usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql--datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin--user=mysql --log-error=/usr/local/mysql/data/lab11g.err --pid-file=/usr/local/mysql/data/lab11g.pid< /dev/null >> /usr/local/mysql/data/lab11g.err 2>&1160625 16:01:35 mysqld_safe Number of processes running now: 0160625 16:01:35 mysqld_safe mysqld restarted [root@lab11g mysql]# ps -ef| grep mysqldroot      7306 5918  0 15:50 pts/2    00:00:00 /bin/sh bin/mysqld_safe--user=mysqlmysql     7662  7306 17 16:01pts/2    00:00:00/usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql--datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin--user=mysql --log-error=/usr/local/mysql/data/lab11g.err--pid-file=/usr/local/mysql/data/lab11g.pidroot      7688 5918  0 16:01 pts/2    00:00:00 grep mysqld

*************************************************

3.3 mysqld

 

我们也可以使用mysqld去启动,如下: 

[root@lab11g mysql]#bin/mysqld --user=mysql &[1] 7772[root@lab11g mysql]#2016-06-25 16:02:49 0 [Warning] TIMESTAMP with implicit DEFAULT value isdeprecated. Please use --explicit_defaults_for_timestamp server option (seedocumentation for more details).2016-06-25 16:02:49 0[Note] bin/mysqld (mysqld 5.6.31) starting as process 7772 ...2016-06-25 16:02:49 7772[Note] Plugin 'FEDERATED' is disabled.2016-06-25 16:02:49 7772[Note] InnoDB: Using atomics to ref count buffer pool pages2016-06-25 16:02:49 7772[Note] InnoDB: The InnoDB memory heap is disabled2016-06-25 16:02:49 7772[Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins2016-06-25 16:02:49 7772[Note] InnoDB: Memory barrier is not used2016-06-25 16:02:49 7772[Note] InnoDB: Compressed tables use zlib 1.2.32016-06-25 16:02:49 7772[Note] InnoDB: Using Linux native AIO2016-06-25 16:02:49 7772[Note] InnoDB: Using CPU crc32 instructions2016-06-25 16:02:49 7772[Note] InnoDB: Initializing buffer pool, size = 128.0M2016-06-25 16:02:49 7772[Note] InnoDB: Completed initialization of buffer pool2016-06-25 16:02:49 7772[Note] InnoDB: Highest supported file format is Barracuda.2016-06-25 16:02:49 7772[Note] InnoDB: 128 rollback segment(s) are active.2016-06-25 16:02:49 7772[Note] InnoDB: Waiting for purge to start2016-06-25 16:02:49 7772[Note] InnoDB: 5.6.31 started; log sequence number 16260172016-06-25 16:02:49 7772[Note] Server hostname (bind-address): '*'; port: 33062016-06-25 16:02:49 7772[Note] IPv6 is not available.2016-06-25 16:02:49 7772[Note]   - '0.0.0.0' resolves to '0.0.0.0';2016-06-25 16:02:49 7772[Note] Server socket created on IP: '0.0.0.0'.2016-06-25 16:02:49 7772[Note] Event Scheduler: Loaded 0 events2016-06-25 16:02:49 7772[Note] bin/mysqld: ready for connections.Version: '5.6.31'  socket: '/tmp/mysql.sock'  port: 3306 MySQL Community Server (GPL)

通过mysqld启动,异常后无法自动重启,如下: 

[root@lab11g mysql]# ps -ef| grep mysqldmysql     7772 5918  3 16:02 pts/2    00:00:00 bin/mysqld --user=mysqlroot      7803 5918  0 16:03 pts/2    00:00:00 grep mysqld[root@lab11g mysql]# kill-9 7772[root@lab11g mysql]#[1]+  已杀死                  bin/mysqld --user=mysql[root@lab11g mysql]# ps -ef| grep mysqldroot      8032 5918  0 16:14 pts/2    00:00:00 grep mysqld

安装mysql其实就是个初始化以及启动进程和实例,安装实际上不用安装,mysql就是个二进制程序,如下:

[root@lab11g bin]# filemysqldmysqld: ELF 64-bit LSBexecutable, AMD x86-64, version 1 (SYSV), for GNU/Linux 2.6.9, dynamicallylinked (uses shared libs), not stripped

另外还有个debug的版本,可以通过gdb来进行调试,并打印出内部的信息。 

[root@lab11g bin]# filemysqld-debugmysqld-debug: ELF 64-bitLSB executable, AMD x86-64, version 1 (SYSV), for GNU/Linux 2.6.9, dynamicallylinked (uses shared libs), not stripped

*************************************************

3.4 mysql.server

 

执行了cpsupport-files/mysql.server /etc/init.d/mysql.server, 可以通过mysql.server来启停 

[root@lab11g mysql]# ps -ef| grep mysqldroot     15400 5918  0 22:24 pts/2    00:00:00 /bin/sh bin/mysqld_safe--user=mysqlmysql    15490 15400 13 22:24 pts/2    00:00:01 /usr/local/mysql/bin/mysqld--basedir=/usr/local/mysql --datadir=/usr/local/mysql/data--plugin-dir=/usr/local/mysql/lib/plugin --user=mysql--log-error=/usr/local/mysql/data/lab11g.err--pid-file=/usr/local/mysql/data/lab11g.pidroot     15523 5918  0 22:24 pts/2    00:00:00 grep mysqld[root@lab11g mysql]#/etc/init.d/mysql.server stopShutting down MySQL..16062522:24:58 mysqld_safe mysqld from pid file /usr/local/mysql/data/lab11g.pidended[确定][1]+  Done                    bin/mysqld_safe--user=mysql[root@lab11g mysql]# ps -ef| grep mysqldroot     15546 5918  0 22:25 pts/2    00:00:00 grep mysqld

还可以加到开机启动,如下: 

[root@lab11g mysql]#chkconfig --add mysql.server[root@lab11g mysql]#chkconfig --list | grep mysqlmysql.server    0:关闭  1:关闭  2:启用  3:启用  4:启用  5:启用  6:关闭

=================================================

3.4.1 mysql.server stop的实质

 

调用的kill, 所以和mysqladmin不一样,不需要密码,如下:

  'stop')    # Stop daemon. We use a signal here to avoid having to know the    # root password.    if test -s "$mysqld_pid_file_path"    then      mysqld_pid=`cat "$mysqld_pid_file_path"`      if (kill -0 $mysqld_pid 2>/dev/null)      then        echo $echo_n "Shutting down MySQL"        kill $mysqld_pid        # mysqld should remove the pid file when it exits, so wait for it.        wait_for_pid removed "$mysqld_pid" "$mysqld_pid_file_path"; return_value=$?      else        log_failure_msg "MySQL server process #$mysqld_pid is not running!"        rm "$mysqld_pid_file_path"      fi      # Delete lock for RedHat / SuSE      if test -f "$lock_file_path"      then        rm -f "$lock_file_path"      fi      exit $return_value    else      log_failure_msg "MySQL server PID file could not be found!"    fi    ;;[root@lab11g mysql_data]# ll *pid-rw-r----- 1 mysql mysql 5 07-12 20:33 lab11g.pid-rw-rw---- 1 root  root  5 07-12 20:33 mysqld_safe.pid[root@lab11g mysql_data]# cat lab11g.pid 6129[root@lab11g mysql_data]# pidof mysqld9220 9166 9147 6129[root@lab11g mysql_data]# kill 6129      -- 发送一个特定的信号给当前的进程,MySQL捕获信号进行处理,和mysqladmin shutdown一样的处理过程


 

 


0 0
原创粉丝点击