linux系统下安装mysql数据库(mysql-5.7)

前言:

   本文主要介绍如何在linux系统下安装mysql数据库及安装时遇到各种问题该如何解决;

      本次安装使用的linux系统是centos,数据库版本是mysql-5.7。

 一、安装前准备

    root用户登录只linux服务器,在根目录下新建数据库安装目录  /software/mysql;数据库文件数据位置:/data/mysql(可以根据自己的习惯创建)

   然后从oracle官网上下载mysql安装包;可以在自己电脑上先下载再上传到linux服务上,如果linux服务器可以访问外网,也可以直接使用wget命令下载,

   将数据库安装原文件放过在/software文件夹下面,(/software/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz)

    wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz

   

  安装文件准备好后将压缩包解压并重命名

   tar -zxvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz

   mv /software/mysql-5.7.21-linux-glibc2.12-x86_64/  /software/mysql

  

    创建mysql用户组和mysql用户

   groupadd mysql

   useradd -r -g mysql mysql

      

     关联myql用户到mysql用户组中

    chown -R mysql:mysql  /software/mysql/

    chown -R mysql:mysql  /data/mysql/

    chown -R mysql  /software/mysql/

    chown -R mysql  /data/mysql

  

     更改mysql安装文件夹mysql/的权限

    chmod -R 755 /software/mysql/

  

     安装libaio依赖包

   首先查询是否已经安装了libaio包,(yum search libaio),如果已经安装了就不需要安装,若未安装 (yum install libaio)

 二、数据库安装

  初始化mysql

   cd /software/mysql/bin 

   ./mysqld --user=mysql --basedir=/software/mysql --datadir=/data/mysql --initialize

   上面这条命令执行完特别注意一下提示:

   [Note] A temporary password is generated for root@localhost: o*s#gqh)F4Ck

   其中“o*s#gqh)F4Ck”是数据库root用户首次登陆的临时密码;

   如果出现error while loading shared libraries: libnuma.so.1: cannot open shared objec错误是因为libnuma安装的是32位的,而当前系统是64位的,

   则可以执行yum install numactl.x86_64命令,完后重新初始化mysql命令

  启动mysql服务

  启动服务之前先修改mysql配置文件

  首先修改mysql.server文件

  vim /software/mysql/support-files/mysql.server

  将该文件中的“/usr/local”全部替换为“/software”

  然后再修改my.cnf文件

  #vi /etc/my.cnf

  将下面内容复制替换当前的my.cnf文件中的内容

    [client]
    no-beep
    socket =/software/mysql/mysql.sock
    # pipe
    # socket=0.0
    port=3306
    [mysql]
    default-character-set=utf8
    [mysqld]
    basedir=/software/mysql
    datadir=/data/mysql
    port=3306
    pid-file=/software/mysql/mysqld.pid
    #skip-grant-tables
    skip-name-resolve
    socket = /software/mysql/mysql.sock
    character-set-server=utf8
    default-storage-engine=INNODB
    explicit_defaults_for_timestamp = true
    # Server Id.
    server-id=1
    max_connections=2000
    query_cache_size=0
    table_open_cache=2000
    tmp_table_size=246M
    thread_cache_size=300
    #限定用于每个数据库线程的栈大小。默认设置足以满足大多数应用
    thread_stack = 192k
    key_buffer_size=512M
    read_buffer_size=4M
    read_rnd_buffer_size=32M
    innodb_data_home_dir = /data/mysql
      innodb_flush_log_at_trx_commit=0
    innodb_log_buffer_size=16M
    innodb_buffer_pool_size=256M
    innodb_log_file_size=128M
    innodb_thread_concurrency=128
    innodb_autoextend_increment=1000
    innodb_buffer_pool_instances=8
    innodb_concurrency_tickets=5000
    innodb_old_blocks_time=1000
    innodb_open_files=300
    innodb_stats_on_metadata=0
    innodb_file_per_table=1
    innodb_checksum_algorithm=0
    back_log=80
    flush_time=0
    join_buffer_size=128M
    max_allowed_packet=1024M
    max_connect_errors=2000
    open_files_limit=4161
    query_cache_type=0
    sort_buffer_size=32M
    table_definition_cache=1400
    binlog_row_event_max_size=8K
    sync_master_info=10000
    sync_relay_log=10000
    sync_relay_log_info=10000
    #批量插入数据缓存大小,可以有效提高插入效率,默认为8M
    bulk_insert_buffer_size = 64M
    interactive_timeout = 120
    wait_timeout = 120
    log-bin-trust-function-creators=1
    sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLE

    #
    # include all files from the config directory
    #
    !includedir /etc/my.cnf.d

   保存退出

   然后再执行启动命令

      sh /software/mysql/support-files/mysql.server start

      若未修改配置文件就启动会报以下错误:

    ./support-files/mysql.server: line 239: my_print_defaults: command  not  found
    ./support-files/mysql.server: line 259: cd: /usr/ local /mysql:  No  such file  or  directory
    Starting MySQL ERROR! Couldn't find MySQL server (/usr/ local /mysql/bin/mysqld_safe)
   
  启动mysql
    /etc/init.d/mysqld start

     新版本的安装包可能会提示以下错误信息

    Starting MySQL.Logging to '/data/mysql/SZY.err'.
    2018-07-02T10:09:03.779928Z mysqld_safe The file /usr/local/mysql/bin/mysqld
    does not exist or is not executable. Please cd to the mysql installation
    directory and restart this script from there as follows:
    ./bin/mysqld_safe&
    See http://dev.mysql.com/doc/mysql/en/mysqld-safe.html for more information
    ERROR! The server quit without updating PID file (/software/mysql/mysqld.pid).

     这是因为新版本的mysql只认/usr/local/mysql这个路径

   可以修改mysql_safe文件   

    vim /software/mysql/bin/mysqld_safe

    将所有的/usr/local/mysql改为/software/mysql

       登录mysql

    /software/mysql/bin/mysql -u root –p

    输入初始化mysql时生成的临时密码,    for root@localhost:   o*s#gqh)F4Ck

  修改登录密码

    mysql   set password=password('root');

    mysql  grant all privileges on *.* to root@'%' identified by 'root';

    mysql flush privileges;

  完成,此时mysql的登录名和密码都是root。

三、安装问题解决

   1、初始化生成的临时密码忘记了无法登录

    停止mysql服务,删除/data/mysql文件夹下的文件,重新执行初始化命令;会重新生成一个临时密码。

   2、启动mysql服务时提示my.cnf文件无法找到

    

    

  

   

    

    

  

  

猜你喜欢

转载自www.cnblogs.com/zhangyyaf/p/10252240.html
今日推荐