• Linux 安装Mysql数据库


    两种安装方式

    1.下载 rpm包进行安装

    2.在线yum安装

     

     

    一.通过mysql官网下载 rpm包进行安装

    1:查看操作系统信息

    uname -a

    [root@localhost init.d]# uname -a

    Linux localhost.localdomain 

    2.6.32-279.el6.x86_64 #1 SMP Fri Jun 22 12:19:21 UTC 2012 x86_64 x86_64 x86_64 

    GNU/Linux


    2.检测系统是否安装MySQL

    进入系统后,检测是否安装mysql.

    #rpm -qa | grep -i mysql

    若已安装过,会出现以下

    MySQL-server-5.1.61-4.el6.x86_64

    MySQL-client-5.1.61-4.el6.x86_64

     

    可以在这里删除它

    #rpm -ev   MySQL-server-5.1.61-4.el6.x86_64

    # rpm -ev  MySQL-client-5.1.61-4.el6.x86_64

    注意:若删除的时候,出现删除不成功,出现依赖的包,前提必须删除依赖项。

    rpm -ev dovecot-1.0.7-7.el5.x86_64

    3.到mysql官网下载对应版本

    (这里一定要注意,mysql官网使用的是谷歌js,所以页面无法显示 linux版本的下载信息,我这是翻墙下载)

    MySQL-5.6.25-1.linux_glibc2.5.x86_64.rpm-bundle.tar

     

    将其解压到文件夹

    tar -xvf  MySQL-5.6.25-1.linux_glibc2.5.x86_64.rpm-bundle.tar 

    有以下rpm包

    MySQL-client-5.6.25-1.linux_glibc2.5.x86_64.rpm 客户端

    MySQL-devel-5.6.25-1.linux_glibc2.5.x86_64.rpm  开发程序

    MySQL-embedded-5.6.25-1.linux_glibc2.5.x86_64.rpm 嵌入式

    MySQL-server-5.6.25-1.linux_glibc2.5.x86_64.rpm 服务器程序

    MySQL-shared-5.6.25-1.linux_glibc2.5.x86_64.rpm

    MySQL-shared-compat-5.6.25-1.linux_glibc2.5.x86_64.rpm

    MySQL-test-5.6.25-1.linux_glibc2.5.x86_64.rpm   测试库

    安装时会因为依赖关系报错,按照以下顺序安装即可:


     

    4.安装mysql

    直接 rpm -ivh MySQL-* 

    或者分开安装,安装时出现的依赖关系,将集合包解压后按以下顺序安装

      rpm -ivh      mysql-community-common-5.6.x86_64.rpm

      rpm -ivh      mysql-community-libs-5.6.x86_64.rpm

      rpm -ivh      mysql-community-client-5.6.x86_64.rpm

      rpm -ivh      mysql-community-server-5.6.x86_64.rpm

     

    # rpm -ivh MySQL-*
    warning: MySQL-client-5.6.38-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
    Preparing...                          ################################# [100%]
    Updating / installing...
       1:MySQL-devel-5.6.38-1.el7         ################################# [ 14%]
       2:MySQL-client-5.6.38-1.el7        ################################# [ 29%]
       3:MySQL-test-5.6.38-1.el7          ################################# [ 43%]
       4:MySQL-embedded-5.6.38-1.el7      ################################# [ 57%]
       5:MySQL-shared-compat-5.6.38-1.el7 ################################# [ 71%]
       6:MySQL-shared-5.6.38-1.el7        ################################# [ 86%]
       7:MySQL-server-5.6.38-1.el7        ################################# [100%]
    warning: user mysql does not exist - using root
    warning: group mysql does not exist - using root
    warning: user mysql does not exist - using root
    warning: group mysql does not exist - using root
    2017-11-15 11:08:12 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
    2017-11-15 11:08:12 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
    2017-11-15 11:08:12 0 [Note] /usr/sbin/mysqld (mysqld 5.6.38) starting as process 561 ...
    2017-11-15 11:08:12 561 [Note] InnoDB: Using atomics to ref count buffer pool pages
    ……
    2017-11-15 11:08:12 561 [Note] InnoDB: Tablespace and datafile system tables created.
    2017-11-15 11:08:12 561 [Note] InnoDB: Waiting for purge to start
    2017-11-15 11:08:12 561 [Note] InnoDB: 5.6.38 started; log sequence number 0
    A random root password has been set. You will find it in '/root/.mysql_secret'.
    2017-11-15 11:08:13 561 [Note] Binlog end
    2017-11-15 11:08:13 561 [Note] InnoDB: FTS optimize thread exiting.
    2017-11-15 11:08:13 561 [Note] InnoDB: Starting shutdown...
    2017-11-15 11:08:14 561 [Note] InnoDB: Shutdown completed; log sequence number 1625977

    2017-11-15 11:08:14 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use 
    2017-11-15 11:08:14 583 [Note] InnoDB: Using CPU crc32 instructions
    2017-11-15 11:08:14 583 [Note] InnoDB: Initializing buffer pool, size = 128.0M
    2017-11-15 11:08:14 583 [Note] InnoDB: Completed initialization of buffer pool
    2017-11-15 11:08:14 583 [Note] InnoDB: Highest supported file format is Barracuda.
    2017-11-15 11:08:14 583 [Note] InnoDB: 128 rollback segment(s) are active.
    2017-11-15 11:08:14 583 [Note] InnoDB: Waiting for purge to start
    2017-11-15 11:08:14 583 [Note] InnoDB: 5.6.38 started; log sequence number 1625977
    2017-11-15 11:08:15 583 [Note] Binlog end
    2017-11-15 11:08:15 583 [Note] InnoDB: FTS optimize thread exiting.
    2017-11-15 11:08:15 583 [Note] InnoDB: Starting shutdown...
    2017-11-15 11:08:16 583 [Note] InnoDB: Shutdown completed; log sequence number 1625987

    A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER !
    You will find that password in '/root/.mysql_secret'.


    You must change that password on your first connect,
    no other statement but 'SET PASSWORD' will be accepted.
    See the manual for the semantics of the 'password expired' flag.


    Also, the account for the anonymous user has been removed.

    In addition, you can run:
      /usr/bin/mysql_secure_installation

    #建议使用mysql_secure_installatiion 初始化数据库

    which will also give you the option of removing the test database.
    This is strongly recommended for production servers.

    See the manual for more instructions.

    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 /usr/my.cnf and
    will be used by default by the server when you start it.
    You may edit this file to change server settings

    #配置文件在这里

     

    5.启动 停止 mysql

    /etc/init.d/mysql  start

    /etc/init.d/mysql  stop

    [root@localhost init.d]# ./mysql --help

    Usage: mysql  {start|stop|restart|reload|force-reload|status}

    service mysql start

    service mysql stop

    service mysql restart


    6.查看mysql状态

    # netstat -nat

    Active Internet connections (servers and established)

    Proto Recv-Q Send-Q Local Address               Foreign Address             State

    tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN

    tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN

    tcp        0     52 10.0.7.210:22               10.0.7.5:62134              ESTABLISHED

    tcp        0      0 :::3306                     :::*                        LISTEN

    tcp        0      0 :::22                       :::*                        LISTEN

    tcp        0      0 ::1:631                     :::*                        LISTEN

    mysql默认监听端口3306

    或者 

    # service mysql status

     SUCCESS! MySQL running (36523)

     

    7.mysql 相关文档

    查询mysql的配置文件

    rpm -qc MySQL-server-5.6.25-1.linux_glibc2.5.x86_64

    /etc/logrotate.d/mysql

    /etc/my.cnf     默认的MySQL配置文件

     

    mysql的启动位置

    /etc/init.d/mysql

    数据库目录 

    /var/lib/mysql/ 

     

    8.登陆mysql

    第一次登录只需键入mysql 

    [root@gc01vm4 init.d]# mysql

    Welcome to the MySQL monitor.  Commands end with ; or g.

    Your MySQL connection id is 1

    Server version: 5.5.23 MySQL Community Server (GPL)

    Copyright (c) 2000, 2011, 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 -uroot -p 回车

             (输入密码)

    远程登录服务器   mysql -h服务器地址 -u用户名 -p 回车

                    (输入密码)




    2.在线yum安装

    1.查询匹配版本

    #yum list mysql*

    Installed Packages             

    mysql-libs.x86_64                                 5.1.73-8.el6_8                  

    Available Packages

    mysql.x86_64                                                                                                   5.1.73-8.el6_8

    MySQL-python.x86_64                               1.2.3-0.3.c1.1.el6              

    mysql-bench.x86_64                                5.1.73-8.el6_8                  

    mysql-connector-java.noarch                       1:5.1.17-6.el6                 

    mysql-connector-odbc.x86_64                       5.1.5r1144-7.el6                

    mysql-devel.i686                                  5.1.73-8.el6_8                  

    mysql-devel.x86_64                                5.1.73-8.el6_8                  

    mysql-embedded.i686                               5.1.73-8.el6_8                  

    mysql-embedded.x86_64                             5.1.73-8.el6_8                  

    mysql-embedded-devel.i686                         5.1.73-8.el6_8                  

    mysql-embedded-devel.x86_64                       5.1.73-8.el6_8                  

    mysql-libs.i686                                   5.1.73-8.el6_8                  

    mysql-server.x86_64                               5.1.73-8.el6_8                  mysql-test.x86_64                                 5.1.73-8.el6_8

    备注:

    (如果yum里的版本过低,可以增加yum源方式安装新版本)

    增加yum源方式 安装升级 Mysql 

    http://centos2014.blog.163.com/blog/static/24054204420171641830281/

    安装 mysql的客户端 服务器 和 开发包

    # yum install mysql mysql-server mysql-devel

    安装完成

     






     

  • 相关阅读:
    javascript简繁转换函数
    在嵌套的repeater中加ItemDataBound事件
    asp.net url重写方法和步骤
    打开,另存为,属性,打印"等14个JS代码
    php中global的用法
    ini_get
    PHP学习笔记
    PHP isset()与empty()的使用区别详解
    PHP符号说明
    html禁止清除input文本输入缓存
  • 原文地址:https://www.cnblogs.com/centos2017/p/7896806.html
Copyright © 2020-2023  润新知