• 随笔:Linux里mysql的tar包安装


    注明:

    这里提供的是.tar.gz的压缩包

    https://download.csdn.net/download/caodingzheng/12530452

    安装的位置根据需要自己决定,但是配置my.cnf和mysql-server的时候要正确

    这里不涉及权限问题

    操作步骤:

    1、解压mysql的tar包:

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

    并重命名为自己想要的名字,我这里命名为mysql

    mv mysql-5.7.28-linux-glibc2.12-x86_64 mysql

    2、创建my.cnf配置文件

    my.cnf的位置也是自己决定,建议在/etc/mysql下面创建

    详细的my.cnf介绍这里就不说了,我觉得这篇讲的挺详细的,这里附上链接:

    https://www.cnblogs.com/wyy123/p/6092976.html

    根据自己的需求进行配置,其中basedir = ,datadir = ,socket =这三个是肯定要手动配置的,这是我配置的my.cnf

    # For advice on how to change settings please see
    # http://dev.mysql.com/doc/refman/8.0/en/server-configuration-defaults.html
    
    [mysqld]
    port = 3308
    user = root
    #
    # 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 the leading "# " to disable binary logging
    # Binary logging captures changes between backups and is enabled by
    # default. It's default setting is log_bin=binlog
    # disable_log_bin
    #
    # 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
    #
    # Remove leading # to revert to previous value for default_authentication_plugin,
    # this will increase compatibility with older clients. For background, see:
    # https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_default_authentication_plugin
    # default-authentication-plugin=mysql_native_password
    basedir = /home/qc/cdz/luckyframe3.2/mysql
    datadir = /home/qc/cdz/luckyframe3.2/mysql/data
    socket = /home/qc/cdz/luckyframe3.2/mysql/mysql.sock
    max_connections = 100
    #跳过密码输入
    skip-grant-tables
    
    [mysqld_safe]
    log-error = /home/qc/cdz/luckyframe3.2/mysql/data/mysqld.log
    pid-file = /home/qc/cdz/luckyframe3.2/mysql/data/mysqld.pid
    
    [client]
    port = 3308
    socket = /home/qc/cdz/luckyframe3.2/mysql/mysql.sock
    

     3、在解压的安装包里(这里简称mysql)的目录下面有这几个目录:

    bin  data(数据库文件夹,这是自己创建的,解压里面不包括)  docs  include  lib  LICENSE  man  README  share  support-files

    其中support-files里有我们需要的mysql.server(启动、关闭mysql等),以下是文件内容:

    #!/bin/sh
    # Copyright Abandoned 1996 TCX DataKonsult AB & Monty Program KB & Detron HB
    # This file is public domain and comes with NO WARRANTY of any kind
    
    # MySQL daemon start/stop script.
    
    # Usually this is put in /etc/init.d (at least on machines SYSV R4 based
    # systems) and linked to /etc/rc3.d/S99mysql and /etc/rc0.d/K01mysql.
    # When this is done the mysql server will be started when the machine is
    # started and shut down when the systems goes down.
    
    # Comments to support chkconfig on RedHat Linux
    # chkconfig: 2345 64 36
    # description: A very fast and reliable SQL database engine.
    
    # Comments to support LSB init script conventions
    ### BEGIN INIT INFO
    # Provides: mysql
    # Required-Start: $local_fs $network $remote_fs
    # Should-Start: ypbind nscd ldap ntpd xntpd
    # Required-Stop: $local_fs $network $remote_fs
    # Default-Start:  2 3 4 5
    # Default-Stop: 0 1 6
    # Short-Description: start and stop MySQL
    # Description: MySQL is a very fast and reliable SQL database engine.
    ### END INIT INFO
    
    # If you install MySQL on some other places than /usr/local/mysql, then you
    # have to do one of the following things for this script to work:
    #
    # - Run this script from within the MySQL installation directory
    # - Create a /etc/my.cnf file with the following information:
    #   [mysqld]
    #   basedir=<path-to-mysql-installation-directory>
    # - Add the above to any other configuration file (for example ~/.my.ini)
    #   and copy my_print_defaults to /usr/bin
    # - Add the path to the mysql-installation-directory to the basedir variable
    #   below.
    #
    # If you want to affect other MySQL variables, you should make your changes
    # in the /etc/my.cnf, ~/.my.cnf or other MySQL configuration files.
    
    # If you change base dir, you must also change datadir. These may get
    # overwritten by settings in the MySQL configuration files.
    
    basedir=
    datadir=
    
    # Default value, in seconds, afterwhich the script should timeout waiting
    # for server start.
    # Value here is overriden by value in my.cnf.
    # 0 means don't wait at all
    # Negative numbers mean to wait indefinitely
    service_startup_timeout=900
    
    # Lock directory for RedHat / SuSE.
    lockdir='/var/lock/subsys'
    lock_file_path="$lockdir/mysql"
    

    首先cp启动文件放到/etc/init.d目录下,可以改名为mysqld(是不是很眼熟?),也可以改名为其他,个人喜好,然后对其进行配置。下面是我对文件的配置,主要是配置了basedir=和datadir=以及mysqld_pid_file_path=:

    #!/bin/sh
    # Copyright Abandoned 1996 TCX DataKonsult AB & Monty Program KB & Detron HB
    # This file is public domain and comes with NO WARRANTY of any kind
    
    # MySQL daemon start/stop script.
    
    # Usually this is put in /etc/init.d (at least on machines SYSV R4 based
    # systems) and linked to /etc/rc3.d/S99mysql and /etc/rc0.d/K01mysql.
    # When this is done the mysql server will be started when the machine is
    # started and shut down when the systems goes down.
    
    # Comments to support chkconfig on RedHat Linux
    # chkconfig: 2345 64 36
    # description: A very fast and reliable SQL database engine.
    
    # Comments to support LSB init script conventions
    ### BEGIN INIT INFO
    # Provides: mysql
    # Required-Start: $local_fs $network $remote_fs
    # Should-Start: ypbind nscd ldap ntpd xntpd
    # Required-Stop: $local_fs $network $remote_fs
    # Default-Start:  2 3 4 5
    # Default-Stop: 0 1 6
    # Short-Description: start and stop MySQL
    # Description: MySQL is a very fast and reliable SQL database engine.
    ### END INIT INFO
    
    # If you install MySQL on some other places than /usr/local/mysql, then you
    # have to do one of the following things for this script to work:
    #
    # - Run this script from within the MySQL installation directory
    # - Create a /etc/my.cnf file with the following information:
    #   [mysqld]
    #   basedir=<path-to-mysql-installation-directory>
    # - Add the above to any other configuration file (for example ~/.my.ini)
    #   and copy my_print_defaults to /usr/bin
    # - Add the path to the mysql-installation-directory to the basedir variable
    #   below.
    #
    # If you want to affect other MySQL variables, you should make your changes
    # in the /etc/my.cnf, ~/.my.cnf or other MySQL configuration files.
    
    # If you change base dir, you must also change datadir. These may get
    # overwritten by settings in the MySQL configuration files.
    
    basedir=/home/qc/cdz/luckyframe3.2/mysql
    datadir=/home/qc/cdz/luckyframe3.2/mysql/data
    
    # Default value, in seconds, afterwhich the script should timeout waiting
    # for server start.
    # Value here is overriden by value in my.cnf.
    # 0 means don't wait at all
    # Negative numbers mean to wait indefinitely
    service_startup_timeout=900
    
    # Lock directory for RedHat / SuSE.
    lockdir='/var/lock/subsys'
    lock_file_path="$lockdir/mysql"
    

    4、创建mysql用户组合mysql用户

    这一步看自己需求是否需要

    #创建用户组
    groupadd mysql
    
    #创建用户
    useradd -g mysql mysql

    5、启动mysql

    service mysqld start
    #或者
    /etc/init.d/mysqld start

    6、进入mysql安装目录的bin目录下用mysql -u root -p进入mysql界面

    如果是命令的原因可以用./mysql -u root -p

    如果是因为密码的原因可以在my.cnf配置文件里加入skip-grant-tables,然后直接回车就可以

    在mysql界面根据需求更改用户密码,如:

    #进入mysql数据库
    mysql>use mysql;
    #修改root的密码
    mysql>update user set password=password('123456') where user='root';
    #不重启mysql下直接生效
    mysql>flush privileges;
    #退出
    mysql>quit;

    也可以通过bin目录里mysqladmin进行密码修改(如果存在密码需要输入密码再进行修改,如果没有就直接生效)

    ./mysqladmin -u root -p password 123456

    到这里基本mysql安装完毕

  • 相关阅读:
    Python基本数据类型(int str)个人笔记
    LINUX简单操作的笔记
    samba服务配置步骤
    IP地址的初步理解
    apache服务配置步骤
    [已解决]This dependency was not found: * common/stylus/index.styl in ./src/main.js To install it, you can run: npm install --save common/stylus/index.styl
    (转)iFrame高度自适应
    (转)Div左右两侧等高
    (转)Css样式兼容IE6,IE7,FIREFOX的写法
    瀑布流布局代码
  • 原文地址:https://www.cnblogs.com/caodingzheng/p/14007093.html
Copyright © 2020-2023  润新知